Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alert dialog in android should not dismiss

Tags:

android

dialog

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 the dialog always dismiss if data i got from edittext fields is correct or not.

How can we disable this feature.

UPDATED:

I am gettin Pin Code and Confirm Pin Code from the Dialog Box and in onPositive click i have checked to verify the pin codes.

Now if the pin codes matches then it is calling dialog.dismiss() and if not matching then display a Toast.

But in case of pin code not matched it displays me the message and dismiss the dialog.

I dont want that to be happen.

MORE UPDATES:

is there any way that i will disable the OK Button and when data is verified it will enable the positive Button??

Please help

like image 906
Shah Avatar asked Jun 08 '11 07:06

Shah


People also ask

How do I keep my dialog from closing?

AlertDialog dialog = (AlertDialog) getDialog(); dialog. getButton(AlertDialog. BUTTON_POSITIVE). setEnabled(false);

How do I stop dialog close on click outside Android?

Simply, alertDialog. setCancelable(false); prevent user from click outside of Dialog Box.

How do I turn off alerts in dialog?

AlertDialog generally consists of the main title, the message, and two buttons, technically termed as a positive button and a negative button. Both positive and negative buttons can be programmed to perform various actions. By default, the negative button lets close the AlertDialog without any additional lines of code.

Can you have an alert dialog without any buttons if not why?

You can do this very easily. AlertDialog. Builder alertDialogBuilder = new AlertDialog. Builder(context); // set title alertDialogBuilder.


1 Answers

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();
                    }
                });
            }
        });
like image 152
kinghomer Avatar answered Oct 31 '22 09:10

kinghomer