Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent listview.setSelection in case of Recycler View

In the case of a ListView if we want to make a particular item selected we use the setSelection method. How do we do this in case of RecyclerView?

like image 585
user3008777 Avatar asked Dec 09 '14 11:12

user3008777


People also ask

How does RecyclerView differ from ListView?

Simple answer: You should use RecyclerView in a situation where you want to show a lot of items, and the number of them is dynamic. ListView should only be used when the number of items is always the same and is limited to the screen size.

What is Item view in RecyclerView?

A ViewHolder describes an item view and metadata about its place within the RecyclerView. RecyclerView. Adapter implementations should subclass ViewHolder and add fields for caching potentially expensive View. findViewById(int) results.

What are the advantages of using a RecyclerView instead of a ListView?

Because the RecyclerView is much faster and more versatile with a much better API. Things like animating the addition or removal of items are already implemented in the RecyclerView without you having to do anything.


1 Answers

Use RecyclerView LayoutManager to scroll item at position

recyclerView.getLayoutManager().scrollToPosition(position)

like image 147
Libin Avatar answered Sep 19 '22 01:09

Libin