2016-04-26 9 views
0

私は、複数の動的ビューをアンドロイドで作成しています。親フラグメントと子フラグメントのレイアウトを使用しています。ダイナミックビューを作成していますが、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はoverall_sport_performanceレイアウトの1つのTextViewを持っていると私はあなたのフラグメントのビューがoverall_spot_performance.xmlある場合butterknife

+0

今まで何を試しましたか? onViewCreatedをオーバーライドし、この "ButterKnife.bind(this、view);"を追加してください。その方法で –

答えて

0

を使用して、私は本当にこのように行う、あなたのソリューションを理解していないことを利用したい:

@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); 
関連する問題