views:

30

answers:

1

I have a 2d array of strings. I would like to use a spinner to allow users to select values from the 2nd lvl of the array but I would like to display the selection options in a expandablelistview using the values of the 1st lvl of the array as category headers.

Is this possible, can someone point me in the right direction of how this should be implemented ?

+1  A: 

You cannot directly use an ExpandableListView for the Spinner popup, any more than you can directly use a ListView for the Spinner popup. It is what it is, and that is defined by the Spinner class.

Options include:

  • Subclassing Spinner and overriding whatever drives the popup dialog
  • Copying Spinner into your project and replacing whatever drives the popup dialog (if overriding will not work due to method visibility, etc.)
  • Don't use a Spinner, and instead use a Button plus an AlertDialog containing an ExpandableListView, or something like that

In principle, you could override getDropDownView() in your SpinnerAdapter (e.g., ArrayAdapter). However, there is no concept of the drop-down view being disabled, and I assume you would want your category headers to be non-selectable. If, however, selecting a category is acceptable, this approach would be simplest.

CommonsWare