0

BTW: This is for an Android app. Hey guys, I have made a ListView, and I have managed to add data to it. Here some example code of what I have done so far.

String[] gameListFin;
ArrayList<String> gameList = new ArrayList<String>();

gameList.add(someData);
gameListFin = gameList.toArray(new String[gameList.size()]);

listView = (ListView)findViewById(R.id.shortcutsList);
listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, gameListFin));

This works as it should, I have a list view with the items I want. But I need to add a bit of extra data as a subitem to the list view, and I don't know how to do so. So I was wondering if I did this:

String[] gameListFin;
String[] extraFin
ArrayList<String> gameList = new ArrayList<String>();
ArrayList<String> extra = new ArrayList<String>();

gameList.add("1");
gameList.add("2");
gameList.add("3");
gameList.add("4");
extra.add("1 extra");
extra.add("2 extra");
extra.add("3 extra");
extra.add("4 extra");
gameListFin = gameList.toArray(new String[gameList.size()]);
extraFin = extra.toArray(new String[extra.size()]);

How could I set it so that the String Array extraFin can be set to sub items of the list view, so it would say

1
1 extra
----------
2
2 extra
----------
3
3 extra
----------
4
4 extra

Thanks for your time and help, help will be greatly apriciated. zeokila

Alexandre Hitchcox
  • 2,704
  • 5
  • 22
  • 33
  • see http://stackoverflow.com/questions/7916834/android-adding-listview-sub-item-text – mjn Aug 14 '12 at 14:57

2 Answers2

2

You need to use expandableListView instead of listView. http://developer.android.com/reference/android/widget/ExpandableListView.html

1

You must learn custom Adapter to show custom data for ListView

Here you will find a good example

http://redth.info/2010/10/12/monodroid-custom-listadapter-for-your-listview

http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/

Arslan Anwar
  • 18,746
  • 19
  • 76
  • 105