findViewById
@InjectView(R.id.button1) Button button1;
@InjectViews({ R.id.first_name, R.id.middle_name, R.id.last_name }) List<EditText> nameViews;
-
Activity
setContentView(R.layout.main_activity); ButterKnife.inject(this);
-
Fragment
或Adapter
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) {}