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.
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://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList1.html
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);
}
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With