How to focus position using RecyclerView?

0

Hello, I have a problem saving the last view position of the user, eg:

The user sweeps the list and when clicking on a position the app opens a new Activity and when returning to list it returns to the top, in case it would have to return to the position of the last selection.

I've gone through this and managed to solve however I was using the ListView, I used the:

lista = (ListView) findViewById(R.id.lst);    
  Parcelable posicaoFoco;
  posicaoFoco = lista.onSaveInstanceState();    
lista.onRestoreInstanceState(posicaoFoco);

Now I'm using RecyclerView but it does not accept it.

    
asked by anonymous 07.02.2018 / 15:04

2 answers

0

Store the position of the item clicked and when you return you can set a scroll to the position:

recyclerView.scrollToPosition(position);
    
07.02.2018 / 19:24
0

RecyclerView does not have these methods.

However, the LayoutManager it uses has.

You can access them using

Parcelable recyclerViewState = recyclerView.getLayoutManager().onSaveInstanceState()

and

recyclerView.getLayoutManager().onRestoreInstanceState(recyclerViewState)

Note that most of the time there is no need to use them since internally they are used by RecyclerView to save your state.

    
07.02.2018 / 19:44