Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Focusing on a recyclerview item

I am trying to focus on a particular item of a recyclerview. What is the equivalent of the listview.setSelection(position) when using a recyclerview.

like image 322
Alex Kombo Avatar asked Feb 24 '16 14:02

Alex Kombo


People also ask

How to focus particular item in RecyclerView Android?

You can manage and advance focus using keyboard arrows, reflecting this state visibly in the view item. Use can then press shift, then click another item with their mouse to select all items between the focused item and the clicked item. the position of the currently focused item, or RecyclerView#NO_POSITION if none.

How to request focus RecyclerView in Android?

To request focusing an item view, the view must be focusable and you call View. requestFocus() . If the view is not yet laid out at the time you want to focus it, you can call View. requestFocus() as soon as onViewAttachedToWindow() has been called.


1 Answers

You call RecyclerView.scrollToPosition(position) to request the RecyclerView's LayoutManager to scroll to the given position during the next layout pass (it's asynchronous).

To request focusing an item view, the view must be focusable and you call View.requestFocus(). If the view is not yet laid out at the time you want to focus it, you can call View.requestFocus() as soon as onViewAttachedToWindow() has been called.

like image 152
BladeCoder Avatar answered Nov 01 '22 13:11

BladeCoder