java - Non Deprecated findPreference() Method? - Android -


i want detect when preference contained in listview gets clicked, can launch intent manage selection.

i have done in layout xml file:

<preference android:title="about" android:key="mykey"></preference> 

and following in java code:

preference mypref = (preference) findpreference("mykey"); mypref.setonpreferenceclicklistener(new onpreferenceclicklistener() {              public boolean onpreferenceclick(preference preference) {                  //open browser or intent here              }          }); 

but method public preference findpreference (charsequence key) deprecated.

  1. is there non deprecated equivalent?
  2. if not, if use anyway?
  3. how can fragments me task in better way?chek here: preferences without deprecated methods.

here can check xml layout structure activity has, , snapshot of application:

xml:

<?xml version="1.0" encoding="utf-8"?> <preferencescreen xmlns:android="http://schemas.android.com/apk/res/android" >      <preference          android:key="about"          android:title="@string/titleabout"          android:summary="@string/summaryabout"      />      <preference          android:key="labeltaxonomy"          android:title="@string/titlelabeltaxonomy"          android:summary="@string/summarylabeltaxonomy"      />  </preferencescreen> 

snapshot:

snapshopt

after clicking on (or access label taxonomy) preference, i'd open intent of kind (could video or else...the names misleading).

is there non deprecated equivalent?

if using preferencefragment on api level 11+ devices, call findpreference() on it. otherwise, call findpreference() on preferenceactivity, have no choice.

if not, if use anyway?

it work.

how can fragments me task in better way?

api level 11+ introduced preferencefragment way of constructing contents of preferenceactivity. welcome use them, if still supporting older devices, cannot use preferencefragment devices.

that being said:

i want detect when preference contained in listview gets clicked, can launch intent manage selection.

you not need java code this. use:

    <preferencescreen             android:title="@string/title_intent_preference"             android:summary="@string/summary_intent_preference">          <intent android:action="android.intent.action.view"                 android:data="http://www.android.com" />      </preferencescreen> 

(as seen in javadocs preferenceactivity)

this create entry in preference ui that, when clicked, start activity specified intent.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -