I have two ExpandableListView that are next to each other. Is it possible to synchronize the scroll in these two ExpandableListView ? For example, when the user scrolls the first ExpandableListView , what would the second one do?

For example, my first three columns are the first ExpandableListView, the last column is the second ExpandableListView.

enter image description here

  • How about pulling onScrollListener in both lists, and assigning a dx value from one list to another? - Silento

1 answer 1

Found such a solution, code in the Activity :

 ExpandableListViewSynchronisationTouchListener expandableListViewSynchronisationTouchListener = new ExpandableListViewSynchronisationTouchListener(this, firstExpandable, secondExpandable); firstExpandable.setOnTouchListener(expandableListViewSynchronisationTouchListener); secondExpandable.setOnTouchListener(expandableListViewSynchronisationTouchListener); firstExpandable.setOnChildClickListener(expandableListViewSynchronisationTouchListener); secondExpandable.setOnChildClickListener(expandableListViewSynchronisationTouchListener); 

The class responsible for synchronizing the two ExpandableListView :

 public class ExpandableListViewSynchronisationTouchListener implements View.OnTouchListener, ExpandableListView.OnChildClickListener, ExpandableListView.OnGroupClickListener, ExpandableListView.OnGroupExpandListener { private static final String TAG = ExpandableListViewSynchronisationTouchListener.class.getSimpleName(); private Context context; private View clickSource; private View touchSource; private View firstExpandable; private View secondExpandable; public ExpandableListViewSynchronisationTouchListener(Context context, View fistExpandable, View secondExpandable) { this.context = context; this.firstExpandable = fistExpandable; this.secondExpandable = secondExpandable; } @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (touchSource == null) { touchSource = view; } if (view == touchSource) { if (view != firstExpandable) { firstExpandable.dispatchTouchEvent(motionEvent); } else if (view != secondExpandable) { secondExpandable.dispatchTouchEvent(motionEvent); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { clickSource = view; touchSource = null; } } return false; } @Override public boolean onGroupClick(ExpandableListView parent, View view, int groupPosition, long id) { if (parent == clickSource) { if (parent == firstExpandable) { Toast.makeText(context, "First expandable id: " + view.getId() + " group position: " + groupPosition, Toast.LENGTH_SHORT).show(); } else if (parent == secondExpandable) { Toast.makeText(context, "Second expandable id: " + view.getId() + " group position: " + groupPosition, Toast.LENGTH_SHORT).show(); } } return false; } @Override public boolean onChildClick(ExpandableListView parent, View view, int groupPosition, int childPosition, long id) { if (parent == clickSource) { if (parent == firstExpandable) { Toast.makeText(context, "First expandable id: " + view.getId() + " group position: " + groupPosition + " child position: " + childPosition, Toast.LENGTH_SHORT).show(); } else if (parent == secondExpandable) { Toast.makeText(context, "Second expandable id: " + view.getId() + " group position: " + groupPosition + " child position: " + childPosition, Toast.LENGTH_SHORT).show(); } } return false; } @Override public void onGroupExpand(int groupPosition) { Log.d(TAG, "Group expand: " + groupPosition); } }