相关疑难解决方法(0)

Android对话框,按下按钮时保持对话框打开

当我按下按钮时,我想保持对话框打开.目前正在关闭.

AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setMessage("Are you sure you want to exit?")

   .setCancelable(false)
   .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int id) {
            MyActivity.this.finish();
       }
   })
   .setNegativeButton("No", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
       }
   });
AlertDialog alert = builder.create();
Run Code Online (Sandbox Code Playgroud)

android dialog

62
推荐指数
3
解决办法
6万
查看次数

按钮单击时关闭自定义警报对话框

我无法关闭警报对话框.我正在使用布局充气器进行对话,所以我不确定在完成它之后我会怎样关闭它.代码如下:

AlertDialog.Builder dialog = new AlertDialog.Builder(AddData.this);
DialogInterface dia = new DialogInterface();

//Create a custom layout for the dialog box
LayoutInflater inflater = (LayoutInflater)AddData.this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.add_rep_1_set, parent, false);

TextView title = (TextView)layout.findViewById(R.id.rep_1_title);
Button add_item = (Button)layout.findViewById(R.id.add_button);

add_item.setOnClickListener(new OnClickListener()
{
        @Override
        public void onClick(View v)
        {
        //Need this to close the alert dialog box
        }
});

title.setText(workout_items[position]);
dialog.setView(layout);
dialog.show();
Run Code Online (Sandbox Code Playgroud)

我无法调用完成,因为它关闭了启动警报对话框的列表视图,并且对我无法使用dialog.dismiss调用.

您认为我应该怎么做才能解决这个问题?

android android-alertdialog

28
推荐指数
4
解决办法
7万
查看次数

标签 统计

android ×2

android-alertdialog ×1

dialog ×1