2013-03-02 38 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