【发布时间】:2012-09-22 01:15:19
【问题描述】:
我在访问 LinearLayout 中的相对布局中的 TextView 时遇到这个问题
假设我在文件 row.xml 中有这些视图
<LinearLayout>
<TextView android:id="@+id/title" />
<RelativeLayout android:id="@+id/a_parent">
<TextView android:id="@+id/a">
</RelativeLayout>
<RelativeLayout android:id="@+id/b_parent">
<TextView android:id="@+id/b">
</RelativeLayout>
</LinearLayout>
现在我想从一个活动中更改 TextViews 的值
LayoutInflater li=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout temp=(LinearLayout) li.inflate(R.layout.row, null);
((TextView)temp.findViewById(R.id.title)).setText("This is title");
RelativeLayout rl=(RelativeLayout)temp.findViewById(R.id.a_parent);
((TextView)rl.findViewById(R.id.a)).setText("an this is the content of a");
我可以成功设置id为'title'的TextView,但是接近最后一行时出现错误。它说错误是由 android.content.res.Resources$NotFoundException: String resource ID #0x1
引起的谁能告诉我出了什么问题,如何修复它,以及为什么代码不能按我预期的那样工作?
谢谢
【问题讨论】:
-
请发布所有 LogCat 错误。
标签: java android android-layout android-xml findviewbyid