My activity using and extending preferences activity as
SettingsUser extends PreferenceActivity
I am using preferenceScreen XML to design my shared Preference and adding it in my activity as
addPreferencesFromResource(R.xml.mypreferences);
For getting my shared preferences I am doing
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
Now I want to add onClick
listener on my shared preference, I see there is a method called OnSharedPreferenceChangeListener
but not onClickListener
, anyone can guide how to handle this case?
You can do it as follows:
Preference infoPreference = findPreference(key);
infoPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
//do something
return true;
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.