【发布时间】:2011-04-12 21:22:14
【问题描述】:
在我的偏好活动中使用简单的EditTextPreference:
<EditTextPreference
android:key="SomeKey"
android:title="@string/some_title"
android:summary="..."
android:numeric="integer"
android:maxLength="2"
/>
有没有办法将此配置值保存为整数?现在似乎它只允许输入数字,但该值仍保存为字符串:
调用:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
int value = preferences.getInt("SomeKey", -1);
扔给我java.lang.ClassCastException: java.lang.String,然后:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String value = preferences.getString("SomeKey", "-1");
成功检索值。
如何让PreferenceActivity默认将值保存为整数?
【问题讨论】:
标签: android sharedpreferences preferenceactivity