Skip to content Skip to sidebar Skip to footer

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: But it doesn't work as I want. As you can see, there is a lot of items which ha

Solution 1:

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.

Post a Comment for "Items In Multiple Columns - Spinner"