同じサブレイアウトを複数回含めたレイアウトがあり、それぞれに異なる役割があります。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<include
android:id="@+id/settings_eco_seekarc"
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/settings_arc" />
<include
android:id="@+id/settings_comfort_seekarc"
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="@layout/settings_arc" />
</LinearLayout>
この方法でビューを見つければうまくいきます:
View eco = root.findViewById(R.id.settings_eco_seekarc);
mEcoSeekArc = (SeekArc) eco.findViewById(R.id.settings_seekarc);
mEcoLeaf = (ImageView) eco.findViewById(R.id.settings_leaf_img);
mEcoText = (TextView) eco.findViewById(R.id.settings_text);
View cmf = root.findViewById(R.id.settings_comfort_seekarc);
mComfortSeekArc = (SeekArc) cmf.findViewById(R.id.settings_seekarc);
mComfortLeaf = (ImageView) cmf.findViewById(R.id.settings_leaf_img);
mComfortText = (TextView) cmf.findViewById(R.id.settings_text);
私は現在、自分のプロジェクトにバターナイフを導入しています。各ビューに簡単に注釈を付けて (以下は明らかに機能しません。その理由はわかります)、含まれている各レイアウト ルートを使用して後でそれらを挿入できることを願っています。
@InjectView(R.id.settings_seekarc)
SeekArc mEcoSeekArc;
@InjectView(R.id.settings_leaf_img)
ImageView mEcoLeaf;
@InjectView(R.id.settings_text)
TextView mEcoText;
@InjectView(R.id.settings_seekarc)
SeekArc mComfortSeekArc;
@InjectView(R.id.settings_leaf_img)
ImageView mComfortLeaf;
@InjectView(R.id.settings_text)
TextView mComfortText;
//then later...
View eco = root.findViewById(R.id.settings_eco_seekarc);
ButterKnife.inject(this, eco);
View cmf = root.findViewById(R.id.settings_comfort_seekarc);
ButterKnife.inject(this, cmf);
ただし、この方法で行うと、2 回目の注入で次のエラーが発生します。
エラー:(81, 13) エラー: 'mEcoSeekArc' で既に挿入された ID 2131493185 に対して @InjectView を使用しようとしています。
私の質問は: このシナリオでバターナイフを使用する方法はありますか?