Using a simple EditTextPreference in my activity preferences:
<EditTextPreference android:key="SomeKey" android:title="@string/some_title" android:summary="..." android:numeric="integer" android:maxLength="2" />
Can this configuration value be saved as an integer? It seems now it just lets you enter numbers, but the value is saved as a string:
Vocation:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); int value = preferences.getInt("SomeKey", -1);
throws me java.lang.ClassCastException: java.lang.String and:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); String value = preferences.getString("SomeKey", "-1");
retrieves the value successfully.
How to make PreferenceActivity to save value as integer by default?
android sharedpreferences preferenceactivity
Laimoncijus Sep 15 2018-10-15T00: 00Z
source share