Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get positive Button in DialogPreference

Is there a way to get the positive button of a DialogPreference in any of its events?

I would like to disable it initially, and make it enabled once a EditText validates.

like image 629
Bridget the Midget Avatar asked Jun 07 '12 12:06

Bridget the Midget


People also ask

How do you set the functionality to the positive button for the alert dialog box?

setPositiveButton() is used to create a positive button in alert dialog and setNegativeButton() is used to invoke negative button to alert dialog. Here setNeutralButton() is used to create a neutral cancel button.

How do you show dialog in Kotlin?

The show() method of AlertDialog. Builder is used to display the alert dialog.

What is alert dialog in android?

Android AlertDialog can be used to display the dialog message with OK and Cancel buttons. It can be used to interrupt and ask the user about his/her choice to continue or discontinue. Android AlertDialog is composed of three regions: title, content area and action buttons.


1 Answers

Simply call

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

If you are using a Dialog Builder though, make sure you call this after builder.create() and before .show()

You can then keep a reference to the dialog and enable the button once your conditions are fulfilled.

like image 177
Guykun Avatar answered Oct 05 '22 19:10

Guykun