无法从ListPreference获取值

时间:2012-04-22 18:44:07

标签: android sharedpreferences android-preferences listpreference

我无法从此类的共享偏好中获取价值。 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); } }
     */
}

}

1 个答案:

答案 0 :(得分:0)

getDefaultSharedPreferences正在采用上下文参数,而DefaultHandler类不是上下文。