我有问题重构SettingsActivity.java。重构设置活动
首先,我伸出PreferenceActivity但它没有考虑 addPreferencesFromResource(R.xml.pref_general),因为它标志着decaprecated以及findPreference(的getString(R.string.pref_location_key)。我已经改变了对PreferenceFragment它上面花了两种方法,但现在解决不了getMenuInflater()膨胀(R.menu.menu_settings,菜单);
而且它显示: “不能解析符号pref_units_keys” 在 bindPreferenceSummaryToValue(findPreference(的getString(R.string.pref_units_key )));
最后在ForecastFragment.java中我找不到这个方法:
private String formatHighLows(double high, double low){
// Data is fetched in Celsius by default.
// If user prefers to see in Fahrenheit, convert the values here.
// We do this rather than fetching in Fahrenheit so that the user can
// change this option without us having to re-fetch the data once
// we start storing the values in the 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);
}
也许我需要去申报单位,并在string.xml文件度...
我能做些什么?
这里是链接整个代码:http://pastebin.com/KJRbj6Sd#
你的意思是设置片段?如上所述,尝试'getActivity()。getMenuInflater()'。 – natario