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.
2018 UPDATE Today, the
findPreference
method is depricated. So, to achieve this, just override theonPreferenceTreeClick
method in your Preference fragment. For example:A followup on @jason gilbert's answer
I'm on targetSdkVersion 25, and his answer didn't work, I had to wrap the intent tag with a Preference tag. Example:
You need to use onPreferenceTreeClick event.
For example see http://www.javased.com/index.php?source_dir=platform_packages_apps_phone/src/com/android/phone/MobileNetworkSettings.java
Badr,
You need to set
android:key
for the item, Then in your code you can do...Assuming you use the following in your XML:
Then you can do the following in your code:
to launch a website:
to launch a specific activity:
you can also use "android:mimetype" to set the mimetype.