我需要在执行过程中退出OnClickListner事件,但无法找到执行此操作的命令。尝试使用中断,但只能用于for循环,我正在寻找一个命令,将停止执行过程,而不是杀死或完成活动。如何在执行过程中停止OnClickListener?
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'不会停止在'saveBtn'的'onClick()'方法中执行的其他代码,如果这就是你的想法。无论用户最终点击了什么Button,'AlertDialog'都会立即显示,并且'saveBtn'的'onClick()'中的任何内容都会立即继续。你想要做的就是在onClick()''''''''''''''''上执行保存。 –