PreferenceActivity in Android -
how can find if preference has been clicked , take action accordingly. in case want logout when preference in preferenceactivity key logout clicked.the following code not working.
pref.registeronsharedpreferencechangelistener(new sharedpreferences.onsharedpreferencechangelistener() { @override public void onsharedpreferencechanged(sharedpreferences sharedpreferences, string key) { if(key.contentequals("preflogout")) { toast.maketext(preferenceactivitydemoactivity.this, "logout clicked", toast.length_long).show(); } } });
xml
<preferencecategory > <preference android:title=logout" android:key="preflogout"/> </preferencecategory>
also tried using
@override public boolean onpreferenceclick(preference preference) { if(preference.getkey().equals("preflogout")) { toast.maketext(preferenceactivitydemoactivity.this, "logout clicked", toast.length_long).show(); } return false; }
but didnt work
according xml should if(key.equals("preflogout")) {...}
Comments
Post a Comment