android – Kotlin合成扩展和几个包含相同的布局

android – Kotlin合成扩展和几个包含相同的布局,第1张

概述如果我有如下布局,如何使用kotlin合成扩展访问视图: 文件:two_days_view.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width=" 如果我有如下布局,如何使用kotlin合成扩展访问视图:

文件:two_days_vIEw.xml

<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:tools="http://schemas.androID.com/tools"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:orIEntation="vertical">    <include        androID:ID="@+ID/day1"        layout="@layout/day_row"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content" />    <include        androID:ID="@+ID/day2"        layout="@layout/day_row"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content" /></linearLayout>

file:day_row.xml

<linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:orIEntation="vertical"       >        <TextVIEw            androID:ID="@+ID/dayname"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content" />    </linearLayout>

如何访问dayname?我找了一些这样的:

day1.dayname.text = "xxx"day2.dayname.text = "sss"

我在Studio中看到我可以访问dayname但是dayname TextVIEw引用了哪一个?

正常,如果我只有一个包含的布局,它工作正常.但现在我有多次包含相同的布局.

我当然可以这样做:

day1.findVIEwByID(R.ID.dayname).text = "xxx"

但我正在寻找好的解决方案. 总结

以上是内存溢出为你收集整理的android – Kotlin合成扩展和几个包含相同的布局全部内容,希望文章能够帮你解决android – Kotlin合成扩展和几个包含相同的布局所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1136786.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存