How can I return data from a RecyclerView adapter?

后端 未结 3 1219
予麋鹿
予麋鹿 2020-12-17 02:41

I have a RecyclerView in which in each object of the RecyclerView I have a checkbox. Each time one of the checkboxes is pressed I would like to ins

3条回答
  •  盖世英雄少女心
    2020-12-17 03:23

    The easiest way is to use EventBus https://github.com/greenrobot/EventBus

    Just register it in your fragment and set @Subscribe method. Build simply class and pass data from adapter to fragment using EventBus.getDefault().post(new YourClass(yourData));

    Another way is use intarfaces.

    Caution!

    When you will use checkbox in your adapter, you must remember old value from checkbox, and set in when list will be scrolled. Then you may be interested SparseBooleanArray

提交回复
热议问题