[Android SDK] A little clarification when using JakeWharton’s ButterKnife

Inside your Activity, respect this order:

@Inject(R.id.textView)
TextView injectedTextView;

protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ButterKnife.inject(this);
    injectedTextView.setText(“whatever”);
    ...
}

Method ButterKnife.inject(context) must be called after setContentView(…), or else you won’t be able to use injectedView.

Thanks JakeWharton for the excellent lib!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s