如何将位置传递给RecyclerView.ViewHolder?

时间:2016-06-06 08:15:04

标签: android

如何将当前位置传递给扩展RecyclerView.ViewHolder的班级?它需要它才能以编程方式创建视图

1 个答案:

答案 0 :(得分:4)

RecyclerView持有人已拥有getAdapterPosition()getLayoutPosition()方法 来自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.