I have 50 items in my recycler view. I want to focus or show specific item like when I click on button 1 it will focus items 10, and when I click on button 2 it will show/focus on items 30 and so on.
You can use the RecyclerView directly for that.
Scroll to item:
recyclerView.smoothScrollToPosition(itemPosition)
recyclerView.scrollToPosition(itemPosition)
If you are looking for how to scroll to that 10th and 30th item then below solution is for you.
recyclerView.getLayoutManager().scrollToPosition(position)
Here position is, in which position you want to scroll
for highlight that item you can change text format like bold or color of that item of recycler view
Happy Coding:)
If you want to highlight a certain items, then pass another arraylist containing ids to be highlighted to your adapter. And create a function usually through an interface that updates that list and reloads all the items in a different manner. and for scroll use smoothScrollToPosition(position)
.
val itemPositionToFocus = 0 // for example the first item
val viewHolder = mRecyclerView.findViewHolderForLayoutPosition(itemPositionToFocus)
viewHolder.itemView.requestFocus()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.