Under Gradle.app, add the following dependencies:
dependencies {
...
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
}
Under MainActivity, Annotate it by @BindView
@BindView(R.id.butterToast) EditText butterToast;
It will replace the line:
private EditText butterToast = (EditText) findViewByID(R.id.butterToast);
Under onCreate(Bundle savedInstanceState){}
ButterKnife.bind(this);
Annotate methods outside onCreate(Bundle savedInstanceState)
@OnClick(R.id.button)
public void submit() {
Toast.makeText(MainActivity.this,
"Hello from Butterknife OnClick annotation", Toast.LENGTH_SHORT).show();
}
Import the following Classes:
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
http://www.vogella.com/tutorials/AndroidButterknife/article.html#exercise-using-butterknife-in-your-android-project
Comments
Post a Comment