简体   繁体   中英

How to link children Views inside an <include /> tag?

below is a snippet copied from And Dev.

<com.android.launcher.Workspace
android:id="@+id/workspace"
android:layout_width="fill_parent"
android:layout_height="fill_parent"

launcher:defaultScreen="1">

<include android:id="@+id/cell1" layout="@layout/workspace_screen" />
<include android:id="@+id/cell2" layout="@layout/workspace_screen" />
<include android:id="@+id/cell3" layout="@layout/workspace_screen" />

</com.android.launcher.Workspace>

Here they demonstrate how to overwrite the ID of the root View or ViewGroup of the included layout.

My question is, is it also possible to overwrite the children's ID through XML?
If not, how am I supposed to link cell2 or cell3's children Views if their IDs were already preset? HierarchyViewer tells me that all included children Views' attributes do not change, including the ID attribute, thus generating multiple Views with the SAME ID.

There is nothing wrong in matching id's. How else would you implement list view items for example?

You can access children views you need by using nested findViewById().

findViewById(cell3).findViewById(child_View_id)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM