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 语句的痛苦.例如拼接时要确保不能忘记添加必要的空格,还 ...
随机推荐
- java 泛型编程学习
先发布,以后有空再修改... 第一次看到<java核心技术卷一>中关于泛型这部分的时候感觉很复杂,似乎有说不完的约束条件,让人难以理解.当时只是囫囵吞枣般过了一遍,也没有看出个什么来.现在 ...
- 通过单元测试理解spring容器以及dubbo+zookeeper单元测试异常处理
一.先说一个结论:单元测试与主项目的spring容器是隔离的,也就是说,单元测试无法访问主项目spring容器,需要自己加载spring容器. 接下来是代码实例,WEB主项目出于运行状态,单元测试中可 ...
- IIS发布问题汇总
1.未能加载文件或程序集“System.Data.SQLite” 在IIS界面选择应用程序池->选择所使用的.net 版本->高级设置->将"使用32位应用程序" ...
- wcf序列化大对象时报错:读取 XML 数据时,超出最大
错误为: 访问服务异常:格式化程序尝试对消息反序列化时引发异常: 尝试对参数 http://tempuri.org/ 进行反序列化时出 错: request.InnerException 消息是“反序 ...
- Twisted
Twisted是一个事件驱动的网络框架,其中包含了诸多功能,例如网络协议,线程,数据库管理,网络操作,电子邮件等 事件驱动 一,注册事件 二,触发事件 自定义事件框架 event_fram.py # ...
- ADO数据库操作
void CSjtestDlg::OnBnClickedButtonAdd() { // TODO: 在此添加控件通知处理程序代码 this->ShowWindow(SW_HIDE); DigA ...
- Javascript中判断变量是 array还是object(是数组还是对象)
段文字是从github上截取由本人翻译过来的. 原文地址:https://github.com/nathansmith/javascript-quiz/blob/master/ANSWERS.md 怎 ...
- Jmeter组件6. SOAP/XML-RPC Request
Jmeter测试SOAP的web services现在有两种方式 第一是使用SOAP/XML-RPC Request组件,第二使用HTTP Request组件 Send SOAPACtion, 同ht ...
- 转@ManyToMany- annotation关系映射篇(下)
原文:http://blog.sina.com.cn/s/blog_6fef491d0100obdd.html 终于要说ManyToMany了 场景:Product和Customer. 先看TestP ...
- webservice wsdl接口配置与调用
准备包 WebRoot/WEB-INF/lib/axis2-adb-1.6.2.jarWebRoot/WEB-INF/lib/axis2-ant-plugin-1.6.2.jarWebRoot/WEB ...