android notifyItemRangeInserted禁用自动滚动 [英] android notifyItemRangeInserted disable autoscroll
问题描述
我正在使用RecyclerView作为数据列表的基础. 我已经实现了基于ArraList的自定义RecyclerView.Adapter.从互联网上获取数据时,我正在运行的代码是:
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.
相关信息:我的适配器具有2个viewHolders-对于位置0,它具有一个视图(viewType为0) 对于列表的其余部分,其视图类型为viewType 1
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
感谢您的帮助!
罗伊
推荐答案
问题就在您的positionStart中.应该是:
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());
}
这篇关于android notifyItemRangeInserted禁用自动滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!