Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I put multiple items on the same line in a ListView?

I have an ArrayList of items that are linked to a custom Adapter. The items are in alphabetical order. I would like my ListView to have a maximum of four items on each line of the ListView with the lines separated alphabetically.

For example:

[ Hi ] [ Hospital ] [ Hotel ] [ HotSpot ]

[ House ]

[ Impossible] [ Improbable ]

So multiple items would be on the same line of the ListView.

Is there a way to use the position variable within the custom Adapter class's getView() method to accomplish this?

Here is an example, sorry for the quality: People Screen

In the image, the backing store, such as ArrayList, would contain those names alphabetized.

like image 254
benkdev Avatar asked Jan 16 '12 04:01

benkdev


2 Answers

You have to implement the CustomListView. on GetView method of the ArrayAdapter of your object.

See below Example:

See this link.

It will realy going to help you.

Enjoy. :)

like image 100
Shreyash Mahajan Avatar answered Nov 02 '22 18:11

Shreyash Mahajan


Yes, in the getView( ) method one of the parameters is a position which can be used to send the relevant view back

public abstract View getView (int position, View convertView, ViewGroup parent)
like image 41
Rajdeep Dua Avatar answered Nov 02 '22 19:11

Rajdeep Dua