2013-03-02 39 views
0

我需要在android.I中显示'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()); 
    } 
+0

当异常显示的对话框? – 2013-03-02 08:06:29

+0

@NAYOSO它显示在对话框 – Techy 2013-03-02 08:07:28

+0

的显示()中,如果可能的话发布日志 – 2013-03-02 08:09:55

回答

0

我想在同一时间多个对话是不可能的。

如果您想显示一系列对话框,可以使用onclick监听器。在一个对话框中,打开下面的对话框。 (dialog interface for the listeners) ,如果你想阻止你的程序,因此用户必须点击对话框上,设置为不取消(setCancelable