android - Cannot get a hold on my Preferences with Unified Preferences -
i use this library create preferenceactivity
. works quite fine far can not set listeners on preference.
that how activity
looks like:
public class prefactivity extends unifiedsherlockpreferenceactivity { @override public void oncreate(bundle savedinstancestate) { setheaderres(r.xml.preference_headers); // set desired preference file , mode (optional) setsharedpreferencesmode(context.mode_private); super.oncreate(savedinstancestate); getsupportactionbar().sethomebuttonenabled(true); getsupportactionbar().setdisplayhomeasupenabled(true); preference p = (preference)findpreference("deletesavedsearches"); p.setonpreferenceclicklistener(new preference.onpreferenceclicklistener() { @override public boolean onpreferenceclick(preference arg0) { //code want return true; } }); } }
this preferencescreen:
<preferencescreen xmlns:android="http://schemas.android.com/apk/res/android" > <preference android:key="deletesavedsearches" android:summary="gespeicherte suchen löschen" android:title="gespeicherte suchen löschen" /> </preferencescreen>
and headers:
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android" xmlns:unified="http://schemas.android.com/apk/res-auto" > <!-- /* ** header definitions identical android:* except preferenceres should reference preference xml file ** unlike native headers these used building single pane version. */ --> <header unified:fragment="com.example.skelett.prefactivity$generalpreferencefragment" unified:preferenceres="@xml/pref_country" unified:title="land" /> <header unified:fragment="com.example.skelett.prefactivity$generalpreferencefragment" unified:preferenceres="@xml/pref_data" unified:title="daten" /> </preference-headers>
in case, p
null
. getpreferencescreen()
returns null
. have keys set in preference xml. missing?
just move findpreference method in onpostcreate , should work:
@override protected void onpostcreate(bundle savedinstancestate) { super.onpostcreate(savedinstancestate); preference p = (preference) findpreference("deletesavedsearches"); p.setonpreferenceclicklistener(new preference.onpreferenceclicklistener() { @override public boolean onpreferenceclick(preference arg0) { // code want return true; } }); }
Comments
Post a Comment