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

1

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.