ButterKnife is library to initialize the views with Annotations.
With the help of Butterknife you have no need to initialize view with findViewBtId().
here we start.
1. Create Project.
2. Open module level build.gradle file.
3. Add below dependencies.
compile 'com.jakewharton:butterknife:8.3.0'
4. Open your Activity and add below line in onCreate() after setContentView.
ButterKnife.bind(this);
5. onCreate() look like:-
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
}
}
6. Create Field variable of view with annotation @BindView(ID_OF_VIEW).
@BindView(R.id.my_textview)
TextView title;
@BindView(R.id.my_button)
Button subtitle;
ButterKnife is very helpful when you have very complex design.
Happy Coding :)
0 Comment(s)