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.
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.
The show() method of AlertDialog. Builder is used to display the alert dialog.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With