Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android notifyItemRangeInserted disable autoscroll

Tags:

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

like image 806
royB Avatar asked Nov 22 '14 16:11

royB


1 Answers

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());
}
like image 90
localhost Avatar answered Sep 23 '22 20:09

localhost