How get an Android ListPreference defined in Xml whose values are integers?

Posted by Rob Kent on Stack Overflow See other posts from Stack Overflow or by Rob Kent
Published on 2010-04-24T17:02:33Z Indexed on 2010/06/13 3:22 UTC
Read the original article Hit count: 660

Is it possible to define a ListPreference in Xml and retrieve the value from SharedPreferences using getInt? Here is my Xml:

<ListPreference android:key="@string/prefGestureAccuracyKey"
    android:title="@string/prefGestureAccuracyTitle" android:summary="@string/prefGestureAccuracyDesc"
    android:entries="@array/prefNumberAccuracyLabels" android:entryValues="@array/prefNumberAccuracyValues"
    android:dialogTitle="@string/prefGestureAccuracyDialog"
    android:persistent="true" android:defaultValue="2"
    android:shouldDisableView="false" />

And I want to get the value with something like: int val = sharedPrefs.getInt(key, defaultValue).

At the moment I have to use getString and parse the result.

© Stack Overflow or respective owner

Related posts about android

Related posts about android-preferences