I am working right now with Android’s SharedPreferences.
I have set some preference binded to EditTextPreference – so content is String type and we access it with:
String defaultValue = "1337";
String value = preferences.getString("key", defaultValue);
But what about we want to work with int value ?
int defaultValue = 1337;
int value = Integer.parseInt(preferences.getString("key", String.valueOf(defaultValue)));
Is there a better way ? Can I somehow set EditTextPreference to be int typed ?
No, sorry. You can create your own custom subclass of
DialogPreference, perhaps even a subclass ofEditTextPreference(not sure how flexible that is), that saves values as an integer value in theSharedPreferences.