2013-11-22 42 views
9

我正在開發一個自定義警報對話框,其中有一個textview和Button的一個android項目, 。當用戶觸摸屏幕時,如何避免取消AlertDialog.Builder對話框?

edt.setText("Enter Comment"); 
    AlertDialog.Builder builder = new AlertDialog.Builder(
        CameraActivity.this); 
      builder.setTitle("Enter your Comment"); 
      lnrt.addView(edt); 
      builder.setView(lnrt); 

      builder.setNegativeButton("SUBMIT", new OnClickListener() { 
       public void onClick(DialogInterface arg0, int arg1) { 
        edText = edt.getText().toString(); 
        new upDb(2).execute(); 
       } 
      }); 

      builder.create(); 
      builder.show(); 

當我觸摸出側對話框時它變得隱藏,如何避免這種情況? 請幫助我。

+2

參見:http://stackoverflow.com/a/15432562/870459,有你的親戚。 –

+0

[如何避免在用戶觸摸屏幕時忽略我的進度對話框]?(http://stackoverflow.com/questions/15432476/how-can-i-avoid-dismissing-my-progress-dialog-當用戶觸摸屏幕) – glenneroo

回答

25

嘗試

builder.setCancelable(false); 

您展示窗口前,它正是你想要的。

+0

謝謝..工作 – Viresh

+0

然後接受答案;) –

1

這將防止您的對話從收盤時的用戶之外對話接觸面積:

dialog.setCanceledOnTouchOutside(false); 
+4

'AlertDialog'沒有方法。 – BlueMice

0

試試這個...

AlertDialog.Builder alert = new AlertDialog.Builder(this); 
... 
... 
alert.setCancelable(false); 
final AlertDialog dialog = alert.create(); 
dialog.setCanceledOnTouchOutside(false); 
dialog.show(); 
+0

它適合我... – indrajeet

相關問題