インフレートされるレイアウトに含まれる要素で Roboguice @InjectView を使用できますか? 要素が最初に @Nullable と宣言されているのは、インフレが完了するまでわからないため、私には正しいようです。ただし、インフレート後、「findViewById」が完了するまで要素はnullのままです。
例として: 次のコードを使用して、メイン レイアウトで膨張する title_layout に含まれる null 許容のテキストビュー (タイトル) を挿入します。
@Nullable @InjectView(R.id.title) TextView title;
@InjectView(R.id.title_info) LinearLayout titleContainer;
そして、 onCreate() メソッドでこれを行います:
setContentView(R.layout.main);
inflater.inflate(R.layout.title_layout, titleContainer);
そして、私はmain.xmlを持っています:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/title_info">
</LinearLayout>
</LinearLayot>
およびtitle_layout.xml :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/title"
android:text="my title" />
</LinearLayot>
インフレートされたビューのタイトル (TextView) は、title_layout がインフレートされた後でも、常にnullです。
これを行う:
setContentView(R.layout.main);
inflater.inflate(R.layout.title_layout, titleContainer);
title = (TextView)findViewById(R.id.title);\
問題を解決します。
@InjectView を使用する方法はありますか?