小编Ara*_*hna的帖子

如何在android中使用元素标记找到xml元素

我在xml中有一个包含许多行和列的表格布局.我已经为表格的每一列提供了一个特定的标签.

现在我想根据某些条件访问特定列.如何让标签与字符串匹配,以便我可以访问该列?

例如,我的xml代码是这样的

<TableLayout>

        <TableRow
            android:padding="10dp"
            android:id="@+id/row1"
            android:layout_height="wrap_content"
            android:weightSum="100"
            android:background="#ffffff"
            android:layout_margin="1dp"
            android:layout_weight="16.66">

            <TextView
                android:text="Day"
                android:textStyle="bold"
                android:clickable="true"             
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="11.11" />


            <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="11.11"
            android:id="@+id/tym1"
            android:tag="1"
            android:text="9:30" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="11.11"
            android:id="@+id/tym2"
            android:tag="2"
            android:text="10:30" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="11.11"
            android:id="@+id/tym3"
            android:tag="3"
            android:text="11:30" />

         <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="11.11"
            android:id="@+id/tym4"
            android:tag="4"
            android:text="12:30" />

          <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="11.11"
            android:id="@+id/tym5"
            android:tag="5"
            android:text="1:30" />

           <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="11.11"
            android:id="@+id/tym6"
            android:tag="6"
            android:text="2:30" />

           <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="11.11"
            android:id="@+id/tym7"
            android:tag="7"
            android:text="3:30" />

           <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="11.11" …
Run Code Online (Sandbox Code Playgroud)

android android-layout

3
推荐指数
1
解决办法
3904
查看次数

标签 统计

android ×1

android-layout ×1