2016-04-26 67 views
0

我用儿童的片段,我创建动态视图父片段和布局创造机器人的多种动态视图和我的片段,但我不能结合使用Butterknife这些动态的观点来绑定动态视图。如何使用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); 

我在overall_sport_performance布局一个TextView的,我想使用,使用butterknife

+0

你有什么试过,直到现在呢?尝试重写onViewCreated并添加此“ButterKnife.bind(这一点,图)。”在那个方法 –

回答

0

我真的不明白你的解决方案,如果你的碎片的观点是overall_spot_performance.xml,这样做:

@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; 
} 

无需动态绑定TextView的。不过,如果你仍然需要动态绑定,你可以使用findById方法。我没有测试它,但应该像这样工作:

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);