是否可以显示单位的偏好(同时仍然只取值)
例如:
具有优先级Distance,它是EditTextPreference 和偏好距离单位是ListPreference
所以当它们显示时会显示:
Distance
value + unit
Distance Unit
unit
示例:
Distance
5 km
Distance Unit
km
然后改变距离单位:
Distance
5 mi
Distance Unit
mi
然而,我真正关心的只是5,但我仍然希望展示它旁边的单位。这可能吗?
由于
答案 0 :(得分:0)
当然可以。只需为您的距离和单位实现自定义onSharedPreferenceChanged(SharedPreferences sharedPreferences,String key)。
使用Distance-key查找您的首选项,并使用setSummary(字符串摘要)将单位附加到距离。
这里有一些奇特的代码:
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals("distance") | key.equals("unit")) {
findPreference("distance").setSummary(sharedPreferences.getString("distance", "0") + sharedPreferences.getString("unit", "km"));
}
}