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