如果我有如下布局,如何使用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"
但我正在寻找好的解决方案.