androiduser-interfacecomboboxspinneruser-friendly

Items in multiple columns - spinner


I'm creating an Android app and I want to put a lot of short items to Spinner. Basically, it works:

Android app - screenshot

But it doesn't work as I want. As you can see, there is a lot of items which have a very short text. It means that user may be forced to scroll a lot to find an item (s)he want. What I want to do is to put items in multiple columns, but I don't know how to do it. I searched in the internet for a while and the only solutions I've found were "how to put multiple columns in 1 item" - what I want is "how to put items in multiple columns".

Thanks.


Solution

  • First you should create your custom spinner adapter. Then, you can put 3 textviews in a row in your list.

    On the getView function of your adapter: 1)Instantiate your custom layout (which has 3 textviews) 2)Give each textview a tag like this:

    String mTag1=String.valueOf((position*3)-2); 
    String mTag2=String.valueOf((position*3)-1); 
    String mTag3=String.valueOf((position*3)); 
    yourtextview1.setTag(mTag1);
    ...
    // in position 1 you'll get 1-2-3, for position 2 it is 4-5-6 etc.
    

    Thus you can assign the same onClickListener to them. (You should do this in getView function too) Finally, on the onClick listener, get the clicked item's tag, convert it to integer (which is your items position on the list), get the item on the list with this position, and set your spinner's text with it.