Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listview scrolls to Top on Item Removed #177

Open
weihansheng opened this issue Aug 13, 2019 · 1 comment
Open

Listview scrolls to Top on Item Removed #177

weihansheng opened this issue Aug 13, 2019 · 1 comment

Comments

@weihansheng
Copy link

I use the following Code in my RecyclerView.Adapter to remove an Item. If the current scroll-position is at the top, everything works fine.

If the scroll-position is somewhere in the middle of the List, the List automatically scrolls to the Top of the View.

How to avoid this behaviour?

notifyItemRemoved(position); if (position != dataList.size()) { notifyItemRangeChanged(position, dataList.size() - position); }

@ZeroCandy
Copy link

I use the following Code in my RecyclerView.Adapter to remove an Item. If the current scroll-position is at the top, everything works fine.

If the scroll-position is somewhere in the middle of the List, the List automatically scrolls to the Top of the View.

How to avoid this behaviour?

notifyItemRemoved(position); if (position != dataList.size()) { notifyItemRangeChanged(position, dataList.size() - position); }

try this:

DiscreteScrollLayoutManager.java

@Override
public void onItemsRemoved(RecyclerView recyclerView, int positionStart, int itemCount) {
    int newPosition = currentPosition;
    if (recyclerViewProxy.getItemCount() == 0) {
        newPosition = NO_POSITION;
    } else if (currentPosition >= positionStart) {
        //if (currentPosition < positionStart + itemCount) {
        if (currentPosition < itemCount) {
            //If currentPosition is in the removed items, then the new item became current
            currentPosition = NO_POSITION;
        }
        newPosition = Math.max(0, currentPosition - itemCount);
    }
    onNewPosition(newPosition);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants