LayoutFlator设置TextView Android时出现问题
嘿,伙计们,我使用两个布局,一个通过主布局文件中的“include”嵌入。 我希望在活动中为主xml设置嵌入的TextView。这是我到目前为止想到的 主xml:date\u list\u layout.xmlLayoutFlator设置TextView Android时出现问题,android,layout,textview,android-inflate,Android,Layout,Textview,Android Inflate,嘿,伙计们,我使用两个布局,一个通过主布局文件中的“include”嵌入。 我希望在活动中为主xml设置嵌入的TextView。这是我到目前为止想到的 主xml:date\u list\u layout.xml <RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" android:layout_height="fill_pa
<RelativeLayout android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/bgoption">
<include layout="@layout/cur"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</RelativeLayout>
}
我没有收到任何错误,但TextView仍然为空。知道我做错了什么吗
谢谢
A只需直接使用
文本视图
:
TextView currency = (TextView) findViewById(R.id.currency);
一旦有了
include
d cur.xml,就不再需要手动充气。它会自动插入到结构中,因此您可以安全地删除附加的LayoutInflater
调用。您可以在TextView中直接使用setText。没有在活动中调用LayoutInflater
setContentView(R.layout.date_list_layout);
TextView currency = (TextView) v.findViewById(R.id.currency);
currency.setText("test");
setContentView(R.layout.date\u list\u layout);
TextView货币=(TextView)v.findViewById(R.id.currency);
currency.setText(“测试”);
尝试将视图直接用作TextView currency=(TextView)findViewById(R.id.currency);(删除“查看”参考v),它可能会帮助您,您可以直接获取包含的布局信息是的,确实如此,谢谢。正如@Ripper指出的:一旦您拥有
include
d cur.xml,您就不再需要手动充气。它会自动插入到结构中,因此您可以安全地删除附加的LayoutInflater
调用。
TextView currency = (TextView) findViewById(R.id.currency);
setContentView(R.layout.date_list_layout);
TextView currency = (TextView) v.findViewById(R.id.currency);
currency.setText("test");