android RecyclerView获得单个Item的ViewHolder

我们在使用RecyclerView时,有时候还需要获取某个Item的viewHolder,具体如下:

LinearLayoutManager layoutManager= new LinearLayoutManager(activity);

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的位置

你可能感兴趣的:(android移动应用开发)