How to get child view from RecyclerView?

前端 未结 11 1950
离开以前
离开以前 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 09:07

    So the recyclerview and your product information are in 2 different fragments yes? You are expecting the recyclerview's views to update when they are not even in foreground? also you are changing adapter data item's data at position event.getSellRecordPosition() , but you are not notifying the adapter that its dataset changed, either by adapter.notifyDataSetChanged() or the other notifyItemChanged(position) methods.

    I'd modify your onEvent() like so:

    @Subscribe
    public void onEvent(SellRecordChangedEvent event){
        sell.getSellRecords().set(event.getSellRecordPosition(), event.getSellRecord());
        sell.recalculate();
        int position = event.getSellRecordPosition();
        MyViewHolder holder = adapter.onCreateViewHolder(yourRecyclerView, 0);
        adapter.onBindViewHolder(holder,position);
        View view = adapter.getView(position);
        bus.post(new TransactionTitleChangedEvent(null, view));
    }
    

    Calling on createViewHolder and next BindViewHolder on your adapter will definitely update the views for that position, then your adapter.getView(position) should return you the latest view.

    Here MyViewHolder is your viewholder class and yourRecyclerview, is the reference to your recycler view

提交回复
热议问题