2012-08-02 62 views
0

我有一種方法,顯示和AlertDialog有3 Buttons;中性,消極和積極。在啓動後退出alertdialog

我希望中立在我的應用程序前用Dialog打開聯繫人應用程序。但是,當我回到我的Activity時,Dialog已關閉,即使它應該是「中性」的,我也沒有放置任何return聲明。

這裏是我的代碼:

public static void showAddFriendDialog(Context ctx1) { 
     final Context ctx = ctx1; 

     //showGetFriendsFromContacts(ctx); 

     // Set an EditText view to get user input 

     final EditText input = new EditText(ctx); input.setHint("name"); 
     final EditText input2 = new EditText(ctx); input2.setHint("firstname"); 
     final EditText input3 = new EditText(ctx); input3.setHint("login/email"); 

     // on est obligé de mettre un layout car on peut que mettre un setview 
     LinearLayout layout = new LinearLayout(ctx); 
     layout.setOrientation(LinearLayout.VERTICAL); 

     layout.addView(input); 
     layout.addView(input2); 
     layout.addView(input3); 

     AlertDialog.Builder builder = new AlertDialog.Builder(ctx); 

     builder.setCancelable(true); 
     builder.setTitle("Add a friend"); 
     builder.setMessage("Fill in the fields you know or get your contact info from your Contact List :"); 

     builder.setView(layout); 

     builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int which) { 

........................ 

      } 
     }); 
     builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int which) { 
       return; 
      } 
     }); 

     builder.setNeutralButton("Contact List", 
       new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int id) { 

         ctx.startActivity(new Intent(null, ContactsContract.Contacts.CONTENT_URI)); 

        } 

     }); 


     builder.setOnCancelListener(new DialogInterface.OnCancelListener() { 
      public void onCancel(DialogInterface dialog) { 
       return; 
      } 
     }); 

     builder.show(); 
    } 

是否有人知道是什麼原因造成的?

回答

1

無論點擊哪個按鈕,默認對話框總是會退出。

建議您實施您的custom dialog以避免這種情況。

相關問題