I want to use a ViewStub with ButterKnife, This is what I've done:
public class ExampleFragment extends Fragment {
@InjectView ( R.id.stub )
ViewStub mStub;
/* A TextView in the ViewStub */
@InjectView ( R.id.text )
@Optional
TextView mText;
@Override
public View onCreateView ( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState ) {
View rootView = inflater.inflate ( R.layout.rootview, container, false );
ButterKnife.inject ( this, rootView );
mStub.setLayoutResource ( R.layout.stub_layout );
View inflated = mStub.inflate ();
ButterKnife.inject ( mStub, inflated );
mText.setText("test.");
return rootView;
}
}
and the log says:
mText is a null object reference
I have no idea now, any advice is welcome. Thanks!
View inflated = mStub.inflate (); ButterKnife.inject (this, inflated );
– BasingerButterKnife.inject ( this, rootView );
, somStub
becomes null. Now I useTextView mText = ( TextView ) inflated.findViewById ( R.id.text );
instead :( Thanks anyway! – Daedal