Reputation: 4599
In my app I have a Custom listview with some textviews and Image view like following image.
My requirement is when we tap on a list row it should expand and when tap on it again or tap on any other row it should collapse. Expanded row should be like this
Contents of the expanded row is dynamic, some times no data and some times more values. It should look like in the 2nd image. Please give a solution for this.
Upvotes: 7
Views: 11025
Reputation: 54332
You are looking for ExpandableListView.
Expandable ListView bydefault has two levels. First is called the "Group View" and the second level is called the "Child View". You can simply achieve by making use of the Custom Adapter sample from the very first link I have provided.
here are few links which will get you started,
http://about-android.blogspot.in/2010/04/steps-to-implement-expandablelistview.html
http://www.techienjoy.com/android-expandable-list-dynamically-created-example.php
EDIT 1
To make only child expanded at a particular time, add this,
explist.setOnGroupExpandListener(new OnGroupExpandListener() {
public void onGroupExpand(int groupPosition) {
for(int i=0; i<myExpAdapter.getGroupCount(); i++) {
if(i != groupPosition) {
explist.collapseGroup(i);
}
}
}
});
Upvotes: 10