Sundar_Mob
Sundar_Mob

Reputation: 155

Synchronize two ListView positions when you scroll from both list views Android

I have two ListViews. Is there any way to synchronize the position of ListViews when I scroll both the Lists

Upvotes: 0

Views: 2333

Answers (2)

Tim
Tim

Reputation: 6712

You could use this in your second list view: smoothScrollToPosition(position)

And in your first ListView you could use a OnScrollListener and check the first visible item with getFirstVisiblePosition.

Best wishes, Tim

Upvotes: 0

Rajkiran
Rajkiran

Reputation: 16193

Use the following method to get the scroll position of your first listView-

    private void saveListScrollPosition()
    {
    // save index and top position
    index = _listview1.getFirstVisiblePosition();
    View view = _listview1.getChildAt(0);
    top = (view == null) ? 0 : view.getTop();
    }

And scroll the second listView to that position with-

// restore
    _listview2.setSelectionFromTop(index, top);

Upvotes: 1

Related Questions