android - Error with onPreferenceChange -
here file getting error getsummary() in preference cannot applied (java.lang.charsequence) on preference.getsummary(listpreference.getentries()... , error same getsummary() (java.lang.string) on else statement.
public class settingsactivity extends preferenceactivity implements preference.onpreferencechangelistener{
@override public void oncreate(bundle savedinstancestate) { addpreferencesfromresource(r.xml.pref_general); bindpreferencesummarytovalue(findpreference(getstring(r.string.pref_location_key))); bindpreferencesummarytovalue(findpreference(getstring(r.string.pref_units_key))); super.oncreate(savedinstancestate); } private void bindpreferencesummarytovalue(preference preference){ //set listener watch value change preference.setonpreferencechangelistener(this); //trigger listenter preferences current value onpreferencechange(preference, preferencemanager .getdefaultsharedpreferences(preference.getcontext()) .getstring(preference.getkey(), "")); } @override public boolean onpreferencechange(preference preference, object value){ string stringvalue = value.tostring(); if (preference instanceof listpreference) { //look correct display value in preferences enteries list listpreference listpreference = (listpreference) preference; int prefindex = listpreference.findindexofvalue(stringvalue); if (prefindex >= 0) { preference.getsummary(listpreference.getentries()[prefindex]); } } else{ preference.getsummary(stringvalue); } return true; }
}
getsummary() returns summary, takes no arguments.
you're looking setsumary(charsequence summary)
Comments
Post a Comment