0

I am trying to use an ArrayAdapter with multiple arrays. This i a bit hard to explain for me. What i have are a few Arrays which should be written in one TextView each in my ListView. like -> Array1 contains all the dates for tv1, Array2 all the titles for tv2 and so on.

ArrayAdapter<String> adapter =
                        new ArrayAdapter<String>(getActivity(),
                                R.layout.listview_layout, R.id.lv_date,
                                dates);

so, making an array for all the TextViews shouldn't be that hard, but how could I set whole 'arrays' to the TextViews?

mike.b93
  • 1,929
  • 2
  • 17
  • 30
  • I was able to solve my problem by following this accepted answer: http://stackoverflow.com/questions/16333754/how-to-customize-listview-using-baseadapter – mike.b93 Jul 02 '14 at 15:31

2 Answers2

1

As a rule, it is not recommended to build your data in this way. Instead of maintaining 2 String arrays, trying making a single array of a custom class that you build. This class could be very simple and only have 2 public members (String s1, String s2). Then tv1 could pick up the data from s1, and tv2 could pick up the data from s2.

Example:

public class MyData
{
    public String s1;
    public String s2;
}

// In the class with your adapter:
ArrayAdapter<MyData> adapter = //...

It's usually better to extend ArrayAdapter. This allows you to have full control of how you build the listview's item's data. There's plenty of reading material on that on the internet.

Gil Moshayof
  • 16,053
  • 4
  • 41
  • 54
  • could you explain this a little further? I don't quite get it. – mike.b93 Jul 02 '14 at 12:47
  • I'm sorry but i still don't get it. How exactly does this work? I'm really stuck here... Any Sites I can read more about this? – mike.b93 Jul 02 '14 at 14:42
  • ListViews are not the simplest components to use for someone who is new to the topic. Here's a good tutorial you should go over: http://www.vogella.com/tutorials/AndroidListView/article.html – Gil Moshayof Jul 02 '14 at 14:46
  • I was able to solve it by following this accepted answer: http://stackoverflow.com/questions/16333754/how-to-customize-listview-using-baseadapter Thank you for your help. ListView is really complicated to understand for me... jeez – mike.b93 Jul 02 '14 at 15:30
0

Try to make the Custom ListView extends the ArrayAdapter or Base Adapter Class Then You can pass the Multiple parameter and can be easily manageable. here is the Example of Custom ListView.

How to customize listview using baseadapter

Community
  • 1
  • 1
TBI
  • 2,595
  • 1
  • 11
  • 19