eventbus快速使用

引入 eventbus

 compile 'org.simple:androideventbus:1.0.5.1'

1、在数据接收页面—订阅,取消订阅,接收数据

  EventBus.getDefault().register(this);
 EventBus.getDefault().unregister(this);
  @Subscriber(tag = EvenBusTag.PLANTED_SELECT)
    public void onEvent(PlantedSelect plantedSelect) {
        if (lastPlantedSelect != null) {
            InsuranceChose.HomeSecondSecureListBean.ThirdSecureBean lastThirdSecureBean =
                    nameList.get(lastPlantedSelect.fatherPosition).getThirdSecure().get(lastPlantedSelect.position);
            lastThirdSecureBean.setSelect(false);
        }
        InsuranceChose.HomeSecondSecureListBean.ThirdSecureBean thirdSecureBean =
                nameList.get(plantedSelect.fatherPosition).getThirdSecure().get(plantedSelect.position);
        thirdSecureBean.setSelect(true);
        lastPlantedSelect = plantedSelect;
        mAdapter.notifyDataSetChanged();
    }

2、在数据传送的地方—发送数据

  EventBus.getDefault().post(plantedSelect, EvenBusTag.PLANTED_SELECT);

注意 EvenBusTag.PLANTED_SELECT为标记根据他来判断消息接收位置

public interface EvenBusTag {
    /**
     * 选择车型
     */
    String PLANTED_SELECT= "planted_select";
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容