0

i am creating the multiple dynamic views in android and my fragment using the layout of parent fragment and in child fragment i am creating the dynamic views but i am not able to bind those dynamic views using Butterknife.

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
this is the on create 
// Inflate the layout for this fragment
        View view = super.onCreateView(inflater, container, savedInstanceState); this.container.addView(inflater.inflate(R.layout.overall_sport_performance_row, null), 5);

i have one textview in the overall_sport_performance layout and i want to use that using butterknife

anoop ghildiyal
  • 821
  • 10
  • 18
  • What have you tried till now? Try overriding onViewCreated and add this "ButterKnife.bind(this, view);" in that method – sanedroid Apr 26 '16 at 14:07

1 Answers1

0

I don't really understand your solution, if your Fragment's view is overall_spot_performance.xml, do like this:

@BindView(R.id.your_text_view_id)
protected TextView textView;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = View.inflate(getContext(), R.layout.overall_sport_performance_row, null);
    Butterknife.bind(this, view);

    return view;
}

No need to bind the TextView dynamically. However if you still need to bind it dynamically, you can use findById method. I did not test it but should work like this:

View dynamicView = inflater.inflate(R.layout.overall_sport_performance_row, null);
this.container.addView(dynamicView, 5);

TextView textView = ButterKnife.findById(dynamicView, R.id.your_text_view_id);
josemigallas
  • 3,761
  • 1
  • 29
  • 68