Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 351
Mariusz Avatar asked Oct 23 '25 12:10

Mariusz


2 Answers

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

yourRecyclerView.smoothScrollToPosition(0);
like image 178
Masoud Mokhtari Avatar answered Oct 26 '25 02:10

Masoud Mokhtari


using https://stackoverflow.com/a/54899984/8144663 only wont resolve your issue.

You will need to call smoothScrollToPosition() in the next frame like,

recyclerview.post(new Runnable() {
            @Override
            public void run() {
                 recycleview.smoothScrollToPosition(n);
            }
        });
like image 27
Sandip Savaliya Avatar answered Oct 26 '25 03:10

Sandip Savaliya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!