0

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 ?

user2416728
  • 400
  • 4
  • 8
  • 25

3 Answers3

2
  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.

Szymon
  • 42,577
  • 16
  • 96
  • 114
  • suppose the 3 list contains firstName,lastName,userName then how it should be done...i mean how a single list contain three different fields ?? – user2416728 Mar 25 '14 at 10:40
  • You need to create a class that will hold all 3 strings. Then you can have a list of objects of that class. – Szymon Mar 25 '14 at 10:42
0

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.

BlackBeard
  • 145
  • 6
0

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.

Community
  • 1
  • 1
Saket
  • 2,945
  • 1
  • 29
  • 31