Skip to content

个人模式,避免ID重复

Drowning Coder edited this page Nov 14, 2018 · 1 revision

当涉及到大型项目时,多人协作往往是一个问题,当所有人都维护一套ComponentId,合并代码时解决冲突往往是很大的问题,并且不可能所有的楼层都是全局打通的类型,所以这里提供一种个人开发模式。

用法

  • 1.使用attach注解,绑定对应class
@ComponentType(
        value = PersonId.VIEWHOLDER,
        layout = R.layout.person_item_layout,
        //class类型,对应到映射表的key
        attach = PersonModel.class
)
public class PersonVH extends RecyclerView.ViewHolder implements IComponentBind<PersonModel> {
    private TextView tvName;

    public PersonVH(View itemView) {
        super(itemView);
        tvName = itemView.findViewById(R.id.tv_name);
    }

    @Override
    public void onBind(int pos, PersonModel item) {
        //tvName.findViewById(R.id.tv_name);
        tvName.setText(item.name);
    }

    @Override
    public void onUnBind() {

    }
}
  • 2.调用SlotContext.attachRule绑定对应的Class
SlotContext slotContext =
                new ToolKitBuilder<PersonModel>(this)
                        //注册绑定的类型,对应获取映射表
                        .attachRule(PersonModel.class).build();
Clone this wiki locally