How to get child view from RecyclerView?

前端 未结 11 1872
离开以前
离开以前 2020-12-24 08:18

I am trying to get child view by position. I could get view when one item is clicked:

rvSellRecords.addOnItemTouchListener(new RecyclerItemClickListener(         


        
相关标签:
11条回答
  • 2020-12-24 08:48
    RecyclerView.ViewHolder holder = recycleView.findViewHolderForAdapterPosition(position);
    ImageView imageView = holder.itemView.findViewById(R.id.iv_product);
    

    This is a supplement to @Ravi Teja's answer. You can get the viewHolder from the recyclerView using position of the particular item, then get a particular view from the viewHolder as shown above

    0 讨论(0)
  • 2020-12-24 08:48

    it helped me, make a 100 ms delay before manipulate it, like this:

    Handler handler = new Handler();        
    mHandler.postDelayed(new Runnable() {
    @Override
    public void run() {
    // rcv is my recyclerview
    rcvStatus.getChildAt(1).setBackground(getActivity().getResources().getDrawable(R.drawable.disabled));
    // or:
    rcvStatus.getChildAt(1).setClickable(false);
    }
    }, 100);
    
    0 讨论(0)
  • 2020-12-24 08:51

    You can use RecyclerView's LayoutManager for it.

    View view = layoutManager.findViewByPosition(position)
    
    0 讨论(0)
  • 2020-12-24 08:53

    just put this method in your code and you can call it as you likes

     void someMagicalMethodWhichReturnsViewByPosition(int position){
             //I assumes child views are CardView
             CardView c  = (CardView)rvSellRecords.getItem(int position);
             ///optional codes
             //////////
        }
    
    0 讨论(0)
  • 2020-12-24 08:55

    I post an answer because which is really complex to findviews() from RecyclerView.

    @Joe: After spending 4hours found one answer. Which gives me the proper view of the index.

    mAdapter is adapter of RecyclerView        
    View v = recyclerView.findViewHolderForItemId(mAdapter.getItemId(index/position)).itemView; 
    

    Now just access your views by: v.findViewById(R.id.edittext) OR any id.

    0 讨论(0)
  • 2020-12-24 08:59

    Use recyclerView.findViewHolderForLayoutPosition(position) or reyclerView.findViewHolderForAdapterPosition(position) to get the viewholder for postion. Then you can access any child from your viewholder.

    Checkout Recyclerview

    0 讨论(0)
提交回复
热议问题