0

Before marking this question duplicate, I know there are few threads going on this particular topic but they are few years old (2012-13) and the Android APIs have changed since then. Furthermore, I have tried those resolutions but either they are not working anymore or since I have bound my ExpandableListView with an ExpandableListAdapter (extending BaseExpandableListAdapter), the solutions are not working.

Here is my problem: I have one ExpandableListView fetching data from static file with the help of ExpandableListAdapter extending BaseExpandableListAdapter. I have implemented getChildView() and getGroupView() methods within the adapter to show the Group Items and Child Items.

What I am not able to achieve is the smooth auto scrolling of the selected clicked item to the top. Something like this: Auto scrolling in ExpandableListView

The solution listed in above thread (ListView.setSelection(position)) is not working in my case. I have tried it. Similarly solution like (android:transcriptMode="disabled or smoothScroll or normal") or (ExpandableListView.smoothScrollToPositionFromTop(scrollTo, 0)) are not giving the desired results. I am not sure what wrong. There is no error or warning or anything.

There are few threads that says to call your ExpandableListView in onGroupExpand() method of the adapter. First, this method is no longer there but I suppose they are referring to the now getChildView() method. But here the items are fetched from the View convertView which is the XML layout of the child items and I don't have ExpandableListView in this layout. I have it in my MainActivity.

Maybe I am getting confused somewhere for this simple issue. Can someone please guide what I am missing and how I can achieve the desired results?

Community
  • 1
  • 1
Harry_S
  • 233
  • 4
  • 10
  • Did you try the onGroupExpanded answer on http://stackoverflow.com/questions/12762958/auto-scrolling-in-expandablelistview? onGroupExpanded has not been deprecated (https://developer.android.com/reference/android/widget/BaseExpandableListAdapter.html#onGroupExpanded(int)). – thecoolmacdude Jun 03 '16 at 19:19

1 Answers1

0

I had the same problem. In child i had only one TextView, which was binded. The point of all was, that in the moment of scrolling to "expanded group" was height of this TextView unknown, due to binding. Text was setted later. So, i set that manually in my adapter:

@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    InfoModelView info = (InfoModelView) getChild(groupPosition,childPosition);

    SubitemBinding binding = DataBindingUtil.inflate(LayoutInflater.from(this.context),R.layout.elv_child, parent, false);

    if (info != null){
        binding.setInfo(info);
        binding.lblListItem.setText(info.getDescription());
    }

    return binding.getRoot();
}

I thing, now i don't need no more all that staff around binding.