Skip to content

Instantly share code, notes, and snippets.

@Kolyall
Created November 15, 2017 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kolyall/8a46ed040032af961ec39101a62febed to your computer and use it in GitHub Desktop.
Save Kolyall/8a46ed040032af961ec39101a62febed to your computer and use it in GitHub Desktop.
viewStub and Butterknife example
public class EstadoActual extends Fragment {
// this controls work perfect
@InjectView(R.id.txtWork1) AutoCompleteTextView txtWork1;
@InjectView(R.id.txtWork2) EditText txtWork2;
// this controls are inside the viewstub,
@InjectView(R.id.viewstub) ViewStub viewStub;
MyDynamicView myDynamicView;
.. .. ...
// class (inner in this example) that has stuff from your stub
public class MyDynamicView {
@InjectView(R.id.txtDontWork1) EditText txtDontWork1;
@InjectView(R.id.txtDontWork1) EditText txtDontWork2;
public MyDynamicView(View view) {
Butterknife.inject(this, view);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.festadoactual, container, false);
ButterKnife.inject(this, rootView);
... ..
View viewFromStub = viewStub.inflate();
myDynamicView = new MyDynamicView(viewFromStub); // this is the main point where you configure your view
Fill();
return rootView;
}
private void Fill(){
txtWork1.setText("Hello 1");
txtWork2.setText("Hello 2");
myDynamicView.txtDontWork1.setText("Don't Work 1"); // This should work for you now
myDynamicView.txtDontWork2.setText("Don't Work 2");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment