How does one declare the type of an Android preference?
Posted
by David R.
on Stack Overflow
See other posts from Stack Overflow
or by David R.
Published on 2010-03-16T18:54:53Z
Indexed on
2010/03/17
9:31 UTC
Read the original article
Hit count: 246
I have a preferences.xml that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference
android:name="Sample"
android:enabled="true"
android:persistent="true"
android:summary="Sample"
android:defaultValue="3.0"
android:title="Sample"
android:key="sample" />
</PreferenceScreen>
When I do sp.getString("sample", "3.0"), it works fine and returns a string, but it shouldn't be a string, it should be a float. Running sp.getFloat("sample", 3.0f) throws a ClassCastException because it is a string.
What should I put in the XML so that the preference is stored as a float?
© Stack Overflow or respective owner