android - 如何在执行过程中停止 OnClickListener?

标签 android onclicklistener android-alertdialog

我需要在执行过程中退出 OnClickListner 事件,但是找不到执行此操作的命令。尝试使用break,但只能在for循环上使用,我正在寻找一个仅停止执行过程而不终止或完成 Activity 的命令。

saveBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

        amountEntered = (EditText) findViewById(R.id.amountEntered);
        Integer bal = Integer.parseInt(custBal);
        Integer enteredAmount = Integer.parseInt(amountEntered.getText().toString());

        // check if amount entered is more than the balance:
        if( enteredAmount > bal ){

            final AlertDialog.Builder alertDialog = new AlertDialog.Builder(MakePaymentActivity.this,R.style.MyAlertDialogStyle);
            alertDialog.setTitle("VERIFY AMOUNT");
            alertDialog.setMessage("Is entered amount correct?");
            alertDialog.setNegativeButton("NO",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        //Simply Exit here
                    }
                }
            );
        });

另一个按钮(积极按钮)只会关闭对话框并继续保存。

最佳答案

只需调用alertDialog即可。 dismiss()或警报对话框。 cancel()

关于android - 如何在执行过程中停止 OnClickListener?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43301696/

相关文章:

javascript - AddEventListener 在分配时自动触发

android - AlertDialog MultiChoiceItems - 一次只选择 2 个项目

android - 找不到符号类 RTCClientVideoTracksCallback

android - 在 ViewAnimator 中的按钮上执行(单击())后,Espresso 测试卡住/不活动

android - OnItemClickListener 和 OnClickListener 不适用于 ListView

java - 具有 onclick 帮助的 Recyclerview

android - 显示 AlertDialog 时暂停 Activity

java - arrayAdapter 中的 AlertDialog 不工作

android - 增加android中的网格间距

android - Android底部的选项菜单是否可以永久设置?