Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android layout 对于膨胀的布局,插入的视图保持为空_Android Layout_Layout Inflater_Roboguice - Fatal编程技术网

Android layout 对于膨胀的布局,插入的视图保持为空

Android layout 对于膨胀的布局,插入的视图保持为空,android-layout,layout-inflater,roboguice,Android Layout,Layout Inflater,Roboguice,我可以在将被充气的布局中包含的元素上使用Roboguice@InjectView吗?在我看来,元素一开始被称为@Nullable是正确的,因为在充气完成之前它们是未知的。但充气后,元素仍然保持为空,直到完成“findViewById” 例如: 我使用以下代码注入一个可为空的textview(标题),该文本视图包含在title_布局中,将在主布局中膨胀: @Nullable @InjectView(R.id.title) TextView title; @InjectView(R.id.title

我可以在将被充气的布局中包含的元素上使用Roboguice@InjectView吗?在我看来,元素一开始被称为@Nullable是正确的,因为在充气完成之前它们是未知的。但充气后,元素仍然保持为空,直到完成“findViewById”

例如: 我使用以下代码注入一个可为空的textview(标题),该文本视图包含在title_布局中,将在主布局中膨胀:

@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:

解决了这个问题


有没有办法使用@InjectView?

我也有同样的问题-原来我是在扩展
活动,而不是
机器人活动,所以它从来没有处理过注入。

谢谢你的回答
<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>
  <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>
setContentView(R.layout.main);
inflater.inflate(R.layout.title_layout, titleContainer);
title = (TextView)findViewById(R.id.title);\