alert dialog in android should not dismiss

前端 未结 3 1824
甜味超标
甜味超标 2021-02-04 14:38

I am making an application and it has an Alert Dialog in it.

Now i am checking some data I got from AlertDialog editTexts in dialog Positive button OnClick method but

相关标签:
3条回答
  • 2021-02-04 15:10

    if you want dismiss dialog whenever you want then you must need to use Custom Dialog instead of Alert Dialog.

    AlertDialog always dismiss when you press Negative or Positive button of AlertDialog.

    For more information about custom dialog then Click here Custom Dialog

    0 讨论(0)
  • 2021-02-04 15:11

    Cap. Thanks for your help. through your guides i have got to know that i can disable the Alert Dialog Button. YES! its possible to disable the buttons.

    Answer is:

    we can disable the button using:

      Button pos =  Dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
      pos.setEnabled(true);
    
    0 讨论(0)
  • 2021-02-04 15:12

    This is the trick (override onClickListener inside onShowListener):

    final AlertDialog d = new AlertDialog.Builder(context)
                    .setView(v)
                    .setTitle(R.string.my_title)
                    .setPositiveButton(android.R.string.ok,
                            new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface d, int which) {
                                    //Do nothing here. We override the onclick
                                }
                            })
                    .setNegativeButton(android.R.string.cancel, null)
                    .create();
    
            d.setOnShowListener(new DialogInterface.OnShowListener() {
    
                @Override
                public void onShow(DialogInterface dialog) {
    
                    Button b = d.getButton(AlertDialog.BUTTON_POSITIVE);
                    b.setOnClickListener(new View.OnClickListener() {
    
                        @Override
                        public void onClick(View view) {
                            // TODO Do something
    
                            //Dismiss once everything is OK.
                            d.dismiss();
                        }
                    });
                }
            });
    
    0 讨论(0)
提交回复
热议问题