preferenceactivity - Why does Android ignore OnPreferenceClickListener() that returns true? -
i defined preferences in xml file following:
<preferencescreen xmlns:android="http://schemas.android.com/apk/res/android"> <preferencescreen android:title="@string/pref_screen" android:key="pref_screen_key"> <checkboxpreference android:defaultvalue="true" android:key="prefs1_key" android:title="@string/prefs1_str" android:summary="@string/prefs1_summary" /> .... inside preferenceactivity override onpreferenceclick() "pref_screen_key":
... findpreference("pref_screen_key").setonpreferenceclicklistener( new onpreferenceclicklistener() { @override public boolean onpreferenceclick(preference preference) { if (flag) { // stuff return true; // according android doc means, click handled } else return false; } so wish android not open view checkboxpreference if flag true, executes stuff (i return true inside onpreferenceclick() indicate click handled , not needed execute default onpreferenceclick() behavior). unfortunately, android handles onpreferenceclick() default behavior , makes stuff @ same time.
is bug in android? there way prevent android showing checkboxpreference after user clicks on preferencescreen?
you're running problems fact flag must declared final accessed inside onpreferenceclicklistener. try encapsulating in class , declaring class final.
to more directly answer question, remember when return true onpreferenceclick(), you're telling system "don't worry, handled it." so, when return true without doing anything, system isn't ignoring you, per se, told nothing when preference clicked.
your code looks similar lines 108-115 of this example. through , may help.
Comments
Post a Comment