Butterknife

Butterknife

findViewById

@InjectView(R.id.button1) Button button1;
@InjectViews({ R.id.first_name, R.id.middle_name, R.id.last_name }) List nameViews;
  • Activity

    setContentView(R.layout.main_activity);
    ButterKnife.inject(this);
    
  • FragmentAdapter

    ButterKnife.inject(this, rootView);
    
    void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }
    

新版改为 @BindView 和 ButterKnife.bind(this);

setOnClickListener

  • 无参数

    @OnClick(R.id.submit)
    public void submit() { //... }
    
  • 附带参数

    @OnClick(R.id.submit)
    public void submit(View view) { //... }
    
  • 多个控件

    @OnClick({ R.id.door1, R.id.door2, R.id.door3 })
    public void pickDoor(DoorView door) {}
    

你可能感兴趣的:(Butterknife)