Android: preference button pressed?

I have a general preferences screen with checkbox list settings, etc. Now I would like to add a button on the general preferences screen so that a dialog box appears when I click on it. I do this and it looks perfect to make a button on the preferences screen:

<Preference android:key="key" android:summary="make pop up dialog" android:title="dialog" /> 

But now I do not know how to do it when pressed. I tried and I can not use onSharedPreferenceChanged because no settings have changed just by clicking. So what would I do to get when the preference button is pressed? Thanks for the help.

+4
source share
1 answer

First, your PreferenceActivity should implement Preference.OnPreferenceClickListener . Then, under the onCreate function, onCreate is called

findPreference(YOUR_KEY_PREF).setOnPreferenceClickListener(this);

and add this function

 @Override public boolean onPreferenceClick(Preference preference) { String key = preference.getKey(); if(key.equals(YOUR_KEY_PREF)){ showYourDialog(); return true; } return false; } 

In your case, YOUR_KEY_PREF has "key"

+5
source

All Articles