android notifyItemRangeInserted disable autoscroll

心已入冬 提交于 2019-12-30 00:53:08

问题


I'm using RecyclerView as the base for my data list. i've implemented custom RecyclerView.Adapter which is based on ArraList. on fetching data from the internet the code that i'm running is:

public void addItems(List<Item> items){

    final int size = data.size();
    data.addAll(items);
    notifyItemRangeInserted(size, items.size());
}

Problem is that for after running this code i'm getting an autoscroll to the bottom of the list (last element is now visible)

Is there a way to disable this? couldn't find any similar questions.

relevant information: my adapter have 2 viewHolders - for position 0 it has a view (with viewType 0) and for the rest of list it has view with viewType 1

Thanks for your help!

Roy


回答1:


Problem is in your positionStart. Should be:

public void addItems(List<QuestItem> items){    
    final int positionStart = data.size() + 1;
    data.addAll(items);
    notifyItemRangeInserted(positionStart, items.size());
}


来源:https://stackoverflow.com/questions/27079899/android-notifyitemrangeinserted-disable-autoscroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!