Where to use butterknife
1)Drawables, String, Boolean, Integer, Color and Dimension resources.
2) static class ViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.image_view)
ImageView imageView;
@BindView(R.id.TextView)
TextView text_view;
ViewHolder(View view) {
super(view);
ButterKnife.bind(this, view);
}
}
Note the same with fragments public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
View view=inflater.inflate(R.layout.xxx,container,false);
ButterKnife.bind(this,view);
return view;
}
Note the same with fragments public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
View view=inflater.inflate(R.layout.xxx,container,false);
ButterKnife.bind(this,view);
return view;
}
3) View lists
@BindViews({ R.id.button_flash, R.id.button_timer, R.id.button_hdr})
List<Button> camControls;
Now we have all the views in one list. Lets write VISIBILITY setter for simple show/hide behavior.
i)final ButterKnife.Setter<View, Integer> VISIBILITY = new ButterKnife.Setter<View,Integer>() {
@Override
public void set(@NonNull View view, Integer value, int index) {
view.setVisibility(value);
}
};
ii)Lambda Expressions
final ButterKnife.Setter<View, Integer> VISIBILITY
= (view, value, index) -> view.setVisibility(value);
ButterKnife.apply(camControls, VISIBILITY, View.GONE);
5)Listener Binding
- @OnCheckedChange
- @OnClick
- @OnLongClick
- @OnEditorAction
- @OnFocusChange
- @OnItemClick
- @OnItemLongClick
- @OnTouch
- @OnTextChanged
No comments:
Post a Comment