gpt4 book ai didi

android - 标签覆盖属性

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:29:31 24 4
gpt4 key购买 nike

如果我有一个布局文件=> res/layout/item.xml :

<?xml version="1.0" encoding="utf-8"?>            
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="60dp"

>

<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="John"
/>

<TextView
android:id="@+id/age"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:text="29" />
</LinearLayout>

我还有另一个布局文件,其内容包括上述几项=> res/layout/main.xml :

<?xml version="1.0" encoding="utf-8"?>            
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:orientation="vertical"
>

<!--How can I override "name" and "age" attribute in the included item layout-->

<include android:id="@+id/student" layout="@layout/tem" />

<include android:id="@+id/teacher" layout="@layout/item" />

<include android:id="@+id/other" layout="@layout/item" />

</LinearLayout>

如你所见,我使用 <include>标签以包含相同的布局。但是,如何为每个包含的项目覆盖 ma​​in.xml 中包含的 item.xml 中的“name”和“age”文本值?

最佳答案

I hope this will work.

View v=(View)findviewbyid(R.id.student);

Textview name=(TextView)v.findviewbyid(R.id.name);

Textview age=(TextView)v.findviewbyid(R.id.age);

关于android - <include> 标签覆盖属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9378535/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com