我无法从此类中的 sharedpreferences 中获得价值。getDefaultSharedPreferences 给出错误“PreferenceManager 类型中的方法 getDefaultSharedPreferences(Context) 不适用于参数 (HandlingXMLStuff)”
我可以从我的主类中获取值,但我不能将它传递给下面显示的类。
public class HandlingXMLStuff extends DefaultHandler {
String Units;
private XMLDataCollected info = new XMLDataCollected();
public String getInformation() {
return info.dataToString();
}
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(this);
String unit = prefs.getString("unitsofmeasure", "Fahrenheit");
Log.d("HandlingXMLStuff", "test" + unit);
// if (Units == "Farenheit") {
if (localName.equals("city")) {
String city = attributes.getValue("data");
info.setCity(city);
Log.d("DeskClockActivity", "test" + city);
} else if (localName.equals("temp_f")) {
String t = attributes.getValue("data");
int temp = Integer.parseInt(t);
info.setTemp(temp);
}
/*
* }/* else if (unit == "C") { if (localName.equals("city")) { String
* city = attributes.getValue("data"); info.setCity(city); } else if
* (localName.equals("temp_c")) { String t =
* attributes.getValue("data"); int temp = Integer.parseInt(t);
* info.setTemp(temp); } }
*/
}
}