How do I pass the current position to my class that extends RecyclerView.ViewHolder
? It needs it in order to create the view programmatically
Asked
Active
Viewed 600 times
1

Kaloyan Roussev
- 14,515
- 21
- 98
- 180
-
in onBindViewHolder you can pass position to your ViewHolder – Amir Jun 06 '16 at 08:17
-
2See [this](http://stackoverflow.com/questions/26245139/how-to-create-recyclerview-with-multiple-view-type). – Eric B. Jun 06 '16 at 08:18
-
You can save index position in your data model for each item and refer to it inside ViewHolder – lubilis Jun 06 '16 at 08:19
1 Answers
5
RecyclerView
holder already has getAdapterPosition()
and getLayoutPosition()
methods
From the Docs:
final int getAdapterPosition()
Returns the Adapter position of the item represented by this ViewHolder.
final int getLayoutPosition()
Returns the position of the ViewHolder in terms of the latest layout pass.

JAAD
- 12,349
- 7
- 36
- 57