Question

I am doing some android development and stuck at a point.

I need to populate a ListView and the data is in 3 different ArrayList of String.

Also i have customised a single list view item(it has three textviews) so that the data from those three different list must go at different textviews.

Any way i can populate this ListView ?

Was it helpful?

Solution

  1. Create a new class with 3 variables to hold 3 strings.

  2. Create an ArrayList of your new class and populate it with 3 strings for each object. (This is instead of 3 separate ArrayLists)

  3. Create a custom ArrayAdapter which will allow you to display those 3 strings and use it for your ListView.

OTHER TIPS

Assuming these 3 lists are of same size and their elements are co-related, then set one of the list to the adapter, then populate all the 3 list data in getView(...)

That should do

For a cleaner approach please consolidate all the 3 different data from the list into 1 class structure and a list of this class.

From what I could understand, you do not need three different ArrayLists for three different data types.

A better (and possibly the only proper approach) would be to store those data in a POJO (Pure old java object) and create an ArrayList of this POJO.

Furthermore, you'll also have to create a custom ArrayAdapter that uses your ArrayList as its underlying data set. Here's a nice tutorial for this:

Custom Adapter for List View

Then simply pass this ArrayList to your custom ArrayAdapter for your ListView.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top