Chris Blank Chris Blank - 26 days ago 13
Android Question

Adding new item to the top of the RecyclerView

I am adding an item to recyclerview position 0 programamticly

public void addQuestion(Question question){
this.questionList.add(0, question);
notifyItemInserted(0);
}


This is working very well and the items do appear in the list at top BUT the user has to scroll up to see the new item.

Is there any trick how the item appear at top and recyclerview is scrolling up automaticly ?

Max Max
Answer

well you can use mRecyclerView.smoothScrollToPosition(int position)

Example:

public void addQuestion(Question question){
    this.questionList.add(0, question);
    notifyItemInserted(0);
    mRecyclerView.smoothScrollToPosition(0);
}

UPDATE:

if you want to make the scrolling to certain item really smooth you can have a look at answer to this question

RecyclerView - How to smooth scroll to top of item on a certain position?

Comments