2017-05-21 157 views
0

我有這樣的代碼,直到:如何保持AlertDialog按鈕被點擊

AlertDialog.Builder builder = new AlertDialog.Builder(activity.this); 
     builder.setMessage("Message") 
       .setTitle("Title"); 
     builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int id) { 
      } 
     }); 

     AlertDialog dialog = builder.create(); 
     dialog.show(); 
     Intent intent = new Intent(this, Menu.class); 
     startActivity(intent); 
     finish(); 

但它顯示AlertDialog的第二和切換到另一個活動。如何讓它等待PositiveButton被點擊?

回答

0
AlertDialog.Builder builder = new AlertDialog.Builder(activity.this); 
    builder.setMessage("Message") 
      .setTitle("Title"); 
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int id) { 

    Intent intent = new Intent(this, Menu.class); 
    startActivity(intent); 
    finish(); 
     } 
    }); 

    AlertDialog dialog = builder.create(); 
    dialog.show(); 
+0

謝謝,我會在5分鐘內接受它 – Jkrr