开发者

Any examples for "onDialogClosed"?

开发者 https://www.devze.com 2023-03-28 01:59 出处:网络
Can anyone give me an example or explain me how i subscribe to the onDialogClosed method of an EditTextPreference?

Can anyone give me an example or explain me how i subscribe to the onDialogClosed method of an EditTextPreference?

http://d开发者_如何学Goeveloper.android.com/reference/android/preference/EditTextPreference.html#onDialogClosed%28boolean%29

I want to know when a dialog had its OK button clicked and then retrive the information from the EditTextPreference.

Is there any examples/tutorials of this available or can anyone point me in the right direction?

Thank you.


Just for completion: Since EditTextPreference is a Preference, you can use a OnPreferenceChangeListener. That will be called when the preference is changed. Check for the EditTextPreferences key in the callback and retrieve the new value to act on it. This is especially useful when the preference can be changed in more than one place or will be changed in the background by your app (e.g. writing defaults back when clicking a "default settings" button), since every change will trigger that callback (when your register it global on your SharedPreferences). The onDialogClosed will only be triggered when the user closed the actual dialog.

If you want to watch the single preference you can also use the EditTextPreference.setOnPreferenceChangedListener() function to assign a listener to that preference only.

OnPreferenceChangeListener documentation


You can make something like that :

@Override
protected void onDialogClosed(boolean positiveResult) {
    if (positiveResult) {
      String text=MyEditText.getText();
    }
    else {
     // cancel hit
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号