How to Get Selected Text and Value Android ListPreference

david picture david · May 27, 2011 · Viewed 32.2k times · Source

The XML file of my ListPreference

<ListPreference android:key="lpBirim" android:title="Birim"
        android:summary="" android:defaultValue="0"  android:persistent="false"/>

How to get the selected text and the selected value?

Answer

qavid picture qavid · Oct 17, 2011

in your PreferenceActivity do something like:

ListPreference listPreference = (ListPreference) findPreference("lpBirim");
CharSequence currText = listPreference.getEntry();
String currValue = listPreference.getValue();