Maintain the position of a RecyclerView when I add data

2

Good I have a problem that when adding data sends me to the beginning of the recycler when in fact what I want is to keep in the current position. This happens every time the user fills the end of the foot to load more data from volley ..

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical" />

the method that detects that it has reached the end

    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (!recyclerView.canScrollVertically(0)) {
                CargarContenido();
            }
        }
    });
    
asked by Yamil Lazzari 27.10.2018 в 23:04
source

1 answer

2

I guess what you try is something similar to the messages in a chat, when a new one arrives, it stays in the position of the last one.

Try with mensajes.scrollToPosition(adaptador.getItemCount()-1); in the Activity where you load the elements of your Recycler.

    
answered by 29.10.2018 / 01:16
source