2012-01-09 34 views
5

Mã của tôi ở bên dưới và hoạt động hoàn hảo khi được gọi từ số onCreate() Tôi không có lỗi hoặc lỗi nào. Nó chỉ không hiển thị.Tại sao AlertDialog của tôi sẽ không hiển thị khi được tạo trong onResume() hoặc onActivityResult()?

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) { 
      finish(); 
     } 
    }) 
    .setNegativeButton("No", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int id) { 
      dialog.cancel(); 
     } 
    }); 
AlertDialog alert = builder.create(); 
alert.show(); 

Trả lời

2

Hãy thử ..

AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this); 
    dlgAlert.setMessage("This is an alert with no consequence"); 
    dlgAlert.setTitle("App Title"); 
    dlgAlert.setPositiveButton("OK", null); 
    dlgAlert.setCancelable(true); 
    dlgAlert.create().show(); 

Gọi .show() trên người xây dựng trong mã của bạn.

+0

Cảm ơn, nó hoạt động từ onResume nhưng vẫn không từ onActivityResult(). Bất kỳ ý tưởng? – znat

+0

Mã onActivityResult() của bạn trông như thế nào? –

Các vấn đề liên quan