Sync Two ListView Positions

I have two lists. Is there a way to synchronize the position of ListViews when scrolling through any of the lists

+4
source share
2 answers

Add AbsListView.OnScrollListener , register with ListView. When the ListView scrolls, the onScrollListener onScroll () method will be launched, then call smoothScrollToPosition () on another ListView to synchronize with the same position.

+2
source

We did it, and it worked for us.

listOne.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent arg1) { listTwo.dispatchTouchEvent(arg1); return false; } }); listOne.setOnScrollListener(new OnScrollListener() { @Override public void onScrollStateChanged(AbsListView arg0, int arg1) { } @Override public void onScroll(AbsListView arg0, int arg1, int arg2, int arg3) { if (l1.getChildAt(0) != null) { Rect r = new Rect(); l1.getChildVisibleRect(l1.getChildAt(0), r, null); l2.setSelectionFromTop(l1.getFirstVisiblePosition(), r.top); } } }); 
+1
source

All Articles