Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to show selected data into summary of list preferences

i am new to android programming .well in my application i have added the preference class and i am calling the xml preference which is stored in the xml folder of my application.this is the code for it

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <ListPreference android:title="colors" android:key="colors" android:summary="list of colors to choose from " android:entries="@array/list" android:entryValues="@array/lvalues"></ListPreference> </PreferenceScreen>

and in the java class i had written only one line that is this addPreferencesFromResource(R.xml.prefs);

now i am able to show the preference class and also the list some colors data.

my question is on selecting the list preference it should show me the selected preference in to the summary attribute .currently it is showing me as 'list of colors to choose from' what i want is to show the selected color say i have selected white the summary should show me as white.

please help me .

Thank you, maddy.

like image 684
MADDY Avatar asked Jan 26 '26 12:01

MADDY


1 Answers

you can actually do it in xml. Try this:

<ListPreference
android:key="pref_list"
android:title="A list of preferences"
android:summary="%s"
android:entries="@array/pref_list_entries"
android:entryValues="@array/pref_list_entries_values"
android:defaultValue="0" />

your selected value would replace "%s". For further clarification read this post

like image 140
NezSpencer Avatar answered Jan 29 '26 07:01

NezSpencer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!