java - Refactoring Settings Activity -
i´m having problems refactoring settingsactivity.java.
first, extended preferenceactivity didn't take addpreferencesfromresource(r.xml.pref_general) because marks decaprecated findpreference(getstring(r.string.pref_location_key). i've changed preferencefragment , took both methods above cannot resolve getmenuinflater().inflate(r.menu.menu_settings, menu);
furthermore it's showing: "cannot resolve symbol pref_units_keys" in bindpreferencesummarytovalue(findpreference(getstring(r.string.pref_units_key)));
finally in forecastfragment.java cannot method right:
private string formathighlows(double high, double low){ // data fetched in celsius default. // if user prefers see in fahrenheit, convert values here. // rather fetching in fahrenheit user can // change option without having re-fetch data once // start storing values in database sharedpreferences sharedprefs = preferencemanager.getdefaultsharedpreferences(getactivity()); string unittype = sharedprefs.getstring( getstring(r.string.pref_units_key), getstring(r.string.pref_units_metric)); if(unittype.equals(getstring(r.string.pref_units_imperial))){ high = (high * 1.8) + 32; low = (low * 1.8) + 32; }else if(!unittype.equals(r.string.pref_units_metric)){ log.d(log_tag, "unit type not found: " + unittype); }
probably need declare de units , metric in string.xml file...
what can do??
here link entire code: http://pastebin.com/kjrbj6sd#
you need activity reference.
try adding getactivity()
before getmenuinflater()
, , getresources()
before each 1 of getstring()
s.
private string formathighlows(double high, double low){ sharedpreferences sharedprefs = preferencemanager.getdefaultsharedpreferences(getactivity()); string unittype = sharedprefs.getstring( getresources().getstring(r.string.pref_units_key), getresources().getstring(r.string.pref_units_metric)); if(unittype.equals(getresources().getstring(r.string.pref_units_imperial))){ high = (high * 1.8) + 32; low = (low * 1.8) + 32; }else if(!unittype.equals(getresources().getstring(r.string.pref_units_metric))){ log.d(log_tag, "unit type not found: " + unittype); } }