ExpandableListView onExpand always scrolls the extended group up

I am looking for a way to position the expandableListView group on top when it expands. I tried onGroupExpand or in performItemClick ExpandableListView.

setSelectedPositionFromTop (int, int), partialy works, but if it starts while the system starts its own scroll, the list is redistributed and the group is not displayed.

Sorry for the dirty description, but it’s hard to say without showing exactly what I need.

+4
source share
5 answers

I have a solution to this problem. This is not affectionate, but it works fine. Extensible listView messures - this is moving around the number of the child. It seems that the system thinks that the child is the same height as the parent (group), so if you put a child of a different size, this will cause problems with the auto-scroll list.

My solution was to catch the list, to think that he had more children. If my child is twice as large as the group, I simply return information that contains 2 children. Now, since this is a list based on data, I am checking my data whether there is data for 2 children or only 1 if I do not have data for a second child, I know that I can put 0 kind of height as a second child .

It worked great when I had to create a list with a small group, and not with one big child.

Since there was no answer to my question, I am posting it, it can help someone.

-3
source

Change transcription mode to disabled.

android:transcriptmode="disabled" 

in an extensible list layout.

+5
source

Put this in your adapter:

 public void onGroupExpanded(final int groupPosition) { super.onGroupExpanded(groupPosition); listView.setSelectedGroup(groupPosition); } 
+3
source

Try setSelection (groupPosition) in onGroupExpand (int groupPosition).

+1
source

I tried many solutions, but the code below works for me. Hope this code will be helpful for some. Adds OnGroupExpandListener with onGroupExpand use the code below

 public void onGroupExpand(final int groupPosition) { super.onGroupExpand(groupPosition); expandableListView.post(new Runnable() { @Override public void run() { expandableListView.setSelection(groupPosition); if(expandableListView.getChildAt(groupPosition)!=null) expandableListView.requestChildRectangleOnScreen(expandableListView.getChildAt(groupPosition), new Rect(0, 0, expandableListView.getChildAt(groupPosition).getRight(), expandableListView.getChildAt(groupPosition).getHeight()), false); } }); } 
+1
source

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


All Articles