In my preferences.xml I have a preference element like this:
<Preference android:title="About" />
I want to assign onClick
event, so if user would click on it, I would be able to do open new Intent
or browser. I tried to do it like I do with buttons, but this not seem to work.
You need to set android:key
for the item:
<Preference
android:key="myKey"
android:title="About" />
Then you can do the following in your code:
Preference myPref = (Preference) findPreference("myKey");
myPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
// open browser or intent here
return true;
}
});