0

我的 Android 应用程序有一个带有正按钮和 3 单选按钮的对话框。
3 个中有 2 个是错误答案,1 个是正确答案。
当用户选择错误的答案并按 possitiveButton 作为确定时,
我不想关闭对话框并显示 toast 消息说
您的选择不正确。
然后用户可以重新选择另一个答案并按 OK,
如果答案正确,我想关闭对话框。
我想知道按下 possitiveButton 时如何不关闭对话框。

谢谢!

4

2 回答 2

1

我给你举个例子

AlertDialog.builder builder = new Builder(this);
builder.setPositiveButxxxxx(xxxxxx)
{
     onClick(AlertDialog alert)
     {
          //if you want to dissmiss here,
          alert.dismiss();
          //else
          //do nothing
     }
}
于 2013-04-22T15:02:32.067 回答
0

您必须重写 positiveButton 的 Click 方法。

AlertDialog.Builder db = new AlertDialog.Builder(MyActivity.this);
db.setPositiveButton("OK", new 
    DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

       if (rb1.isChecked() || rb2.isChecked() ){  //here make the toast}
            }
        });
       else { //dismiss here}
AlertDialog dialog = db.show();

其中 rb1 和 rb2 是错误的单选按钮

于 2013-04-22T15:02:00.943 回答