栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Android中创建具有多个列的表?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Android中创建具有多个列的表?

我假设您正在谈论的是TableLayout视图,而不是数据库中的表?

如果是这样,这是一个具有三列三行的表的XML示例。

每个元素在表中创建一行,并且该元素内部的每个视图创建一个“列”。我使用过TextViews,但它们可以是ImageViews,EditText等。

<?xml version="1.0" encoding="utf-8"?><TableLayout xmlns:android="http://schemas.android.com/apk/res/android"         android:id = "@+id/RHE"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_weight="0"         android:padding="5dp">     <TableRow android:layout_height="wrap_content">         <TextView  android:id="@+id/runLabel"  android:text="R"  android:layout_height="wrap_content"  />         <TextView  android:id="@+id/hitLabel"  android:text="H"  android:layout_height="wrap_content"  />         <TextView  android:id="@+id/errorLabel"  android:text="E"  android:layout_height="wrap_content"  />     </TableRow>     <TableRow android:layout_height="wrap_content">         <TextView  android:id="@+id/visitorRuns"  android:text="0"  android:layout_height="wrap_content"  />         <TextView  android:id="@+id/visitorHits"  android:text="0"  android:layout_height="wrap_content"  />         <TextView  android:id="@+id/visitorErrors"  android:text="0"  android:layout_height="wrap_content"  />     </TableRow>     <TableRow android:layout_height="wrap_content">         <TextView  android:id="@+id/homeRuns"  android:text="0"  android:layout_height="wrap_content"  />         <TextView  android:id="@+id/homeHits"  android:text="0"  android:layout_height="wrap_content"  />         <TextView  android:id="@+id/homeErrors"  android:text="0"  android:layout_height="wrap_content"  />     </TableRow></TableLayout>

要在代码中动态更改这些内容,您需要执行以下操作:

// reference the table layoutTableLayout tbl = (TableLayout)findViewById(R.id.RHE);// delcare a new rowTableRow newRow = new TableRow(this);// add views to the rownewRow.addView(new TextView(this)); // you would actually want to set properties on this before adding it// add the row to the table layouttbl.addView(newRow);


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/441017.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号