Search code examples
androidandroid-recyclerviewrecyclerview-layout

Item inserted at first position is not visible until scrolling up


Scenario:

  • my adapter supports two different view types: A & B
  • the adapter is notified about 100 items of type A - everything is rendered correctly
  • the adapter is notified about one item of type B insertion using notifyItemRangeInserted at position 0 - this item is "invisible" by default and in order to see it I have to manually scroll up.

How can I get this first item of type B "automatically" visible?


Solution

  • You can use this line of code after notify item of type B:

    yourRecyclerView.smoothScrollToPosition(0);