开发者

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

开发者 https://www.devze.com 2023-02-17 03:54 出处:网络
below is a snippet copied from And Dev. <com.android.launcher.Workspace android:id=\"@+id/workspace\"

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=开发者_JAVA百科"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)

0

精彩评论

暂无评论...
验证码 换一张
取 消