How to send data from recycler adapter to fragment | How to call fragment function from recyclerview adapter

前端 未结 3 1804
攒了一身酷
攒了一身酷 2021-01-13 04:56

I have code in Fragment:

InfoAdapter adapter = new InfoAdapter(getContext(), R.layout.lv_info, infoList );

            listingsView = (RecyclerView) rootVie         


        
3条回答
  •  我在风中等你
    2021-01-13 05:28

    Just pass Fragment instance to adapter.

    For example :

    IN FRAGMENT : recyclerAdapter = new RecyclerAdapter(getActivity(), MyFragment.this); recyclerView.setAdapter(recyclerAdapter); recyclerAdapter.notifyDataSetChanged(); IN ADAPTER : 1. Create adapter constructer like

    MyFragment myFragment;
    public RecyclerAdapter(Context context, MyFragment myFragment){
        this.context = context;
        this.myFragment = myFragment;
    }
    
    1. under onBindViewHolder

    call myFragment.yourMethodName;

提交回复
热议问题