在启动后退出alertdialog

问题描述:

我有一种方法,显示和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(); 
    } 

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

无论点击哪个按钮,默认对话框总是会退出。

建议您实施您的custom dialog以避免这种情况。