I have a simple preference (not EditText preference or ListPreference). I have a method that deletes all files开发者_运维问答 in a directory. I want to do this when user clicks on a preference, but i don't know how to react to a click on a preference.
getPreferenceManager().findPreference("pref_key").setOnPreferenceClickListener(new OnPreferenceClickListener()
{
@Override
public boolean onPreferenceClick(Preference preference)
{
// Do stuff here
}
});
if your preference is stored in an object(togglePref
) you can do this
togglePref.setOnPreferenceClickListener(this);
then the event is:
@Override
public boolean onPreferenceClick(Preference preference) {
}
精彩评论