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";
}

你可能感兴趣的:(eventbus快速使用)