How To Call The Ok Button In The Edittextpreference
Solution 1:
You can extend EditTextPreference to get control over the click handler.
package myPackage;
publicclassCustomEditTextPreferenceextendsEditTextPreference {
publicCustomEditTextPreference(Context context) {
super(context);
}
publicCustomEditTextPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
publicCustomEditTextPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@OverridepublicvoidonClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
// add Handler here
}
super.onClick(dialog, which);
}
}
In the Xml instead of <EditTextPreference/>
reference it like this:
<myPackage.CustomEditTextPreferenceandroid:dialogTitle="Registration Key"android:key="challengeKey"android:title="Registration Key"android:summary="Click here to enter the registration key you received by email."/>
Solution 2:
Actually you can't since the preference is using an internal AlertDialog.Builder
and creates a new dialog every time you click the preference. The next problem is that the dialog builder sets the click listener for you and if you override them you might destroy the close behavior of the button click.
This bothered me since I wanted a preference which only closes on valid input (otherwise a toast is shown and user should press cancel if he can't get it right).
(If you really need a solution for exactly this problem) You can find general solution of a validating DialogPreference
here and a validating EditTextPreference
here which I wrote myself.
Solution 3:
Your preference activity doesn't appear to be implementing a
OnSharedPreferenceChangeListener
You may want to read over the excellent answer to the question: Updating EditPreference
Post a Comment for "How To Call The Ok Button In The Edittextpreference"