How to expand a list line when we click on it as a list

In my application, I have a Custom listview with some text images and an image view, as shown below. enter image description here

My requirement is that when we click on the list line that it should expand, and when we click on it again or click on any other line, it should crash. The extended line should be like this: enter image description here

The contents of the extended string are dynamic, several times more data and several times more values. It should look in the second image. Please give a solution for this.

+6
source share
1 answer

You are looking for an ExpandableListView .

The extensible ListView bydefault has two levels. First called "Group View", and the second level is called "Child View". You can simply achieve using the sample custom adapter from the very first link I provided.

Here are some links to 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 the child extended at a specific time, add it,

explist.setOnGroupExpandListener(new OnGroupExpandListener() { public void onGroupExpand(int groupPosition) { for(int i=0; i<myExpAdapter.getGroupCount(); i++) { if(i != groupPosition) { explist.collapseGroup(i); } } } }); 
+9
source

Source: https://habr.com/ru/post/915878/


All Articles