Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with catching Preference Item click event

I'm building an android application and I have a pretty dumb question -

I've created a preference screen and put in it a list and a checkBox. Now I handled those just fine, using the 'key' attribute that is saved automatically.

My problem comes when I try using a simple Preference Item(they type that you just press it). What is saved in SharedPreference when it's clicked? If nothing, how can I catch the click event?

I can't find an answer anywhere. Thanks a lot!

like image 311
Tofira Avatar asked Dec 17 '22 15:12

Tofira


1 Answers

tofira,

You need to use setOnPreferenceClickListener() for that particular item. See example:

Preference myPref = (Preference) findPreference("myPref");
myPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
    public boolean onPreferenceClick(Preference preference) {
    //handle action on click here
    }
});
like image 124
Will Tate Avatar answered Dec 27 '22 06:12

Will Tate