1

If I add a ListPreference in my settings.xml the framework shows a list-entry that when clicked shows a list of options. Is it possible to show the list "inline" I mean without making the user having to click on the entry to see the list?

What I need is to show the current selected option and then when the user clicks on it, hte list of all the available options to allow the user to pick another one.

I found this example but I wonder how my HTC can show a combo in the Accessibility settings (for "Touch & hold delay").

kingston
  • 11,053
  • 14
  • 62
  • 116

3 Answers3

1

You need to subclass Preference and make it behave like a Spinner or a ListView. Either that, or you can set the android:layout attribute of the <Preference> tag in the XML to return a layout which contains a ListView. Check this question.

Community
  • 1
  • 1
curioustechizen
  • 10,572
  • 10
  • 61
  • 110
  • The solution I'm implementing is to define a layout that contains a Spinner and use that layout as android:layout for my Preference. Is this what you meant? – kingston May 30 '12 at 14:01
  • Yes - that's exactly what I meant. – curioustechizen May 30 '12 at 14:19
  • In the linked question, how did you get the reference to the textbox when you used the layout. I'm now trying to use only a textbox that will show the current option. I have derived from ListPreference. – kingston May 30 '12 at 14:50
  • I derived from `Preference` and used `getLayoutResource()`. – curioustechizen May 30 '12 at 15:08
  • 1
    So this is what I did. I have specified the android:widgetLayout and not the android:layout. In this way the title and the summary are still shown. The layout was a simple FrameLayout with a Spinner. I have derived from Preference and in the constructor with attributes I read the entries and the entriesValues (like ListPreference.java does). Then in onBindView I initialised the Spinner. In the onSelected of the spinner I persist the value (calling persistString). – kingston May 31 '12 at 13:11
  • Ah - this makes sense. I did not know that `android:widgetLayout` makes it so simple to provide a title and summary. – curioustechizen May 31 '12 at 13:35
0

Use Spinner widget. Check documentation here.

Ron
  • 24,175
  • 8
  • 56
  • 97
  • I get a ClassNotFoundException if I try to add a SPinner in the settings xml. I'm using ICS – kingston May 30 '12 at 11:51
  • If I use android.widget.Spinner I get a ClassCastException because the Spinner cannot be cast to android.preference.Preference – kingston May 30 '12 at 12:10
0

Check out this post How do I display the current value of an Android Preference in the Preference summary?

The bottom line is that you need to register a change listener for the preference and manually update the Summary (second line) of the ListPreference using the selected value from the List. The link provides all the information and samples on how do it.

Also, Some people report that using android:summary="%s" works, but I've never gotten that to work in 2.x.

Community
  • 1
  • 1
stuckless
  • 6,515
  • 2
  • 19
  • 27