开发者

Reacting to a click on a preference

开发者 https://www.devze.com 2023-01-04 17:28 出处:网络
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

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) {

}
0

精彩评论

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