我们在使用RecyclerView时,有时候还需要获取某个Item的viewHolder,具体如下:
int firstItemPosition = layoutManager.findFirstVisibleItemPosition();
if (position - firstItemPosition >= 0) {
//得到要更新的item的view
View view = mRecyclerView.getChildAt(position - firstItemPosition+1);
if (null != mRecyclerView.getChildViewHolder(view)){
ProductsViewHolder viewHolder =
(ProductsViewHolder)mRecyclerView.getChildViewHolder(view);
//do something
}
}
position就是当前item的位置。