0

我需要在android中显示'n'自定义对话框。我在while循环外创建了对话框,并在循环内设置了消息。我需要根据循环显示带有不同消息的对话框。但它在 dialog.show() 行中显示 android.view.WindowLeaked 异常。谁能帮我解决我的问题。

我的代码是这样的:

//notif_count is the row count
if(notif_count>0)
{
 dialog = new Dialog[notif_count];
 for(ct=0;ct<notif_count;ct++)
 {
  dialog[ct] = new Dialog(this);
  dialog[ct].requestWindowFeature(Window.FEATURE_NO_TITLE);
  dialog[ct].setContentView(R.layout.custom_dialog_alert);
 }

  cursor.moveToFirst();
  ct = 0;
  do
  {
     dec_name =cursor.getString(cursor.getColumnIndex(Database_Handler.name));

     TextView tv_alert = (TextView)dialog[ct].findViewById(R.id.txt_alert);
     tv_alert.setText( dec_name );

     Button yes = (Button) dialog[ct].findViewById(R.id.btn_yes);
     Button no = (Button) dialog[ct].findViewById(R.id.btn_no);

     yes.setOnClickListener(new OnClickListener()
     {
       public void onClick(View v) 
       {
             Intent intent = new Intent(Intent.ACTION_VIEW);
             intent.setData(Uri.parse(donateurl));
             startActivity(intent);
             ct--;
             dialog[ct].dismiss();
             cursor.close();
             sqldb.close();
             finish();
        }
     });

      no.setOnClickListener(new OnClickListener()
      {
        public void onClick(View v)
        {
           ct--;
           dialog[ct].dismiss();
           cursor.close();
           sqldb.close();
           finish();
        }
      });
      dialog[ct].show();
      ct ++;
     }while(cursor.moveToNext());
   }
4

1 回答 1

0

我认为同时进行多个对话是不可能的。

如果要显示一系列对话框,可以使用 onclick 侦听器。从一个对话框中,打开以下一个。(监听器的对话框界面),如果你想阻止你的程序,所以用户必须点击对话框,设置对话框不可取消(setCancelable

于 2013-03-02T08:19:19.867 回答