android_demo之自动生成动态表格
今天我们学习了如何更好的利用Android 的 layout 布局。
接下来是个简单的栗子去了解这个自动生成的动态的控件(自动生成表格)
这是我们的layout 页面
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="6">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请输入要生成表格的行号列"
android:textSize="15sp"/>
<TableRow
android:gravity="center"
android:layout_marginTop="5dp"
>
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="行"
android:textSize="15sp"/>
<EditText
android:id="@+id/et1"
android:layout_width="100dp"
android:layout_height="wrap_content"/>
</TableRow>
<TableRow
android:gravity="center"
android:layout_marginTop="5dp"
> <TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="列"
android:textSize="15sp" /> <EditText
android:id="@+id/et2"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:numeric="decimal"/>
<!-- decimal 只能输入数字,大于0的数字-->
</TableRow>
<TableRow
android:gravity="center"
>
<Button
android:id="@+id/btnadd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
android:text="确定" />
</TableRow>
</TableLayout>
</LinearLayout>
<TableLayout
android:id="@+id/table"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3"
android:stretchColumns="*"
android:shrinkColumns="*"> </TableLayout>
</LinearLayout>
再看下我们的 mainActivity.class
package com.example.counter; import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow; public class MainActivity extends Activity implements OnClickListener { private Button submit;
private EditText row;
private EditText cloumn;
private TableLayout table; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.canchange);
submit = (Button) findViewById(R.id.btnadd); row = (EditText) findViewById(R.id.et1);
cloumn = (EditText) findViewById(R.id.et2);
table = (TableLayout) findViewById(R.id.table); submit.setOnClickListener(this); } @Override
public void onClick(View v) {
int c = Integer.parseInt(row.getText() + "");
int r = Integer.parseInt(cloumn.getText() + "");
table.removeAllViews();
for (int i = 0; i < c; i++) {
TableRow tr = new TableRow(this); for (int j = 0; j < r; j++) {
Button b = new Button(this); tr.addView(b);
}
table.addView(tr);
}
} }
运行结果:

可以根据自己的需求去动态生成表格,在这里我们要了解这个动态的概念。
大家可以将代码拷贝去自行实现一番。(调皮~)
android_demo之自动生成动态表格的更多相关文章
- ANDROID 自动生成动态表格for
简单的栗子去了解这个自动生成的动态的控件(自动生成表格) /cs-Layout/res/layout/activity_main.xml <LinearLayout xmlns:android= ...
- poi自动生成Ecxel表格和Chart图表
最近因为业务需求,需要做poi自动导出Ecxel表格和Chart折线图的功能. 所以我在网上找到了一篇关于poi生成Chart图表的博客,代码很详细,但是缺少相关注释说明. 想要将它改造成自己需要的样 ...
- 自己写的自动生成动态边框的jquery小插件
思路就是在元素四周添加<ul>列表,然后周期性地改变它的颜色,实现动态的效果,不支持ie7.ie8 预览链接http://gorey.sinaapp.com/myBorder/border ...
- jmeter自动生成报告
从JMeter 3.0开始已支持自动生成动态报告,我们可以更容易根据生成的报告来完成我们的性能测试报告. 如何生成html测试报告 如果未生成结果文件(.jtl),可运行如下命令生成报告: jmete ...
- Jmeter系列-自动生成html报告
从JMeter 3.0开始已支持自动生成动态报告,我们可以更容易根据生成的报告来完成我们的性能测试报告. 如何生成html测试报告 如果未生成结果文件(.jtl),可运行如下命令生成报告: jmete ...
- 自动把动态的jsp页面(或静态html)生成PDF文档,并且上传至服务器
置顶2017年11月06日 14:41:04 阅读数:2311 这几天,任务中有一个难点是把一个打印页面自动给生成PDF文档,并且上传至服务器,然而公司框架只有手动上传文档,打印时可以保存为PDF在本 ...
- Java利用poi生成word(包含插入图片,动态表格,行合并)
转(小改): Java利用poi生成word(包含插入图片,动态表格,行合并) 2018年12月20日 09:06:51 wjw_11093010 阅读数:70 Java利用poi生成word(包含插 ...
- Vue+Element的动态表单,动态表格(后端发送配置,前端动态生成)
Vue+Element的动态表单,动态表格(后端发送配置,前端动态生成) 动态表单生成 ElementUI官网引导 Element表单生成 Element动态增减表单,在线代码 关键配置 templa ...
- java web(七): mybatis的动态sql和mybatis generator自动生成pojo类和映射文件
前言: MyBatis 的强大特性之一便是它的动态 SQL.如果你有使用 JDBC 或其它类似框架的经验,你就能体会到根据 不同条件拼接 SQL 语句的痛苦.例如拼接时要确保不能忘记添加必要的空格,还 ...
随机推荐
- linux基础学习
1.默认不写端口号的就是80端口 本地ip:localhost或者127.0.0.1 2.用户管理 id和whoami:可以查看当前用户 who和w查看当前已经登录的用户 (1)添加用户,用户默认的家 ...
- css中 input的button默认原始的样子
以往我们写css时,让一行文字垂直居中. 会设置line-height等于height比如: 当我把这个原理 放在button上时 会是这个样子的. 以下都是火狐浏览器环境 有没有发现一个现象,他们 ...
- [转]Amazon DynamoDB – a Fast and Scalable NoSQL Database Service Designed for Internet Scale Applications
This article is from blog of Amazon CTO Werner Vogels. -------------------- Today is a very exciting ...
- web页面设计基本原则
1.对齐. 不对齐看起来糟糕极了.简直一片混乱,会给人一种很不专业的印象.对齐让页面更漂亮一些,更重要的是便于更好的传达信息. 2.去掉糟糕的边框.边框会产生一种分离感. 3.亲密性. 元素相互靠近看 ...
- Hibernate中evict方法和clear方法说明
Hibernate中evict方法和clear方法说明 先创建一个对象,然后调用session.save方法,然后调用evict方法把该对象清除出缓存,最后提交事务.结果报错: Exception i ...
- 关于reset.css的疑问:为什么一定要重置浏览器样式?
自开始做前端算起,我所做过的每一个项目中都会有一个reset.css,也就是重置样式表.我现在想想都不知道第一次是从哪儿弄来的一个重置样式表.快五年了,好像从来都没有质疑过关于重置样式表的内容. 这样 ...
- Bootstrap文件上传插件File Input的使用
基于Metronic的Bootstrap开发框架经验总结(5)--Bootstrap文件上传插件File Input的使用 Bootstrap文件上传插件File Input是一个不错的文件上传控件, ...
- Ms sql行转列。汇总
SQL行转列汇总 PIVOT 用于将列值旋转为列名(即行转列),在 SQL Server 2000可以用聚合函数配合CASE语句实现 PIVOT 的一般语法是:PIVOT(聚合函数(列) FOR 列 ...
- selenium+phantomjs爬取动态页面数据
1.安装selenium pip/pip3 install selenium 注意依赖关系 2.phantomjs for windows 下载地址:http://phantomjs.org/down ...
- jQuery学习笔记(在js中增加、删除及定位控件的操作)
代码内容很多都是从amazeui直接copy过来的,先声明,请不要说在下抄袭- - <!-------------------- HTML代码 ----------------------> ...