简单的栗子去了解这个自动生成的动态的控件(自动生成表格)

/cs-Layout/res/layout/activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" > <TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:gravity="center_vertical"
android:text="请输入行:"
android:textSize="20sp" /> <EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="请输入数字!"
android:numeric="decimal" />
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" > <TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:gravity="center_vertical"
android:text="请输入列:"
android:textSize="20sp" /> <EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="请输入数字!"
android:numeric="decimal" > <requestFocus />
</EditText>
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" > <Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="一键自动生成表格" />
</LinearLayout>
</LinearLayout> <TableLayout
android:id="@+id/flout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TableLayout> </LinearLayout>

activity_main.xml

/cs-Layout/src/com/example/cs_layout/MainActivity.java

package com.example.cs_layout;

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 {
private Button submit;
private EditText cloumn;
private EditText run;
private TableLayout flout; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// cloumn = ;
submit = (Button) findViewById(R.id.button1);
cloumn = (EditText) findViewById(R.id.editText1);
run = (EditText) findViewById(R.id.editText2);
flout = (TableLayout) findViewById(R.id.flout); submit.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
flout.removeAllViews();
new MainActivity().shows(cloumn, run, flout, MainActivity.this); }
}); } public void shows(EditText cloumn, EditText run, TableLayout flout,
Activity a) {
int c = Integer.parseInt(cloumn.getText() + ""); // 将输入进来的数转整数
int r = Integer.parseInt(run.getText() + ""); TableLayout table = new TableLayout(a); // 表格布局
table.setWeightSum(1); // 权重
// table.setColumnStretchable(0, false);
for (int i = 0; i < c; i++) {
TableRow tr = new TableRow(a); for (int j = 0; j < r; j++) {
Button b = new Button(a); // b.setText(j);
tr.addView(b);
}
table.addView(tr);
}
flout.addView(table);
} public void color() { } }

MainActivity.java

ANDROID 自动生成动态表格for的更多相关文章

  1. android_demo之自动生成动态表格

    今天我们学习了如何更好的利用Android 的 layout 布局. 接下来是个简单的栗子去了解这个自动生成的动态的控件(自动生成表格) 这是我们的layout 页面 <?xml version ...

  2. poi自动生成Ecxel表格和Chart图表

    最近因为业务需求,需要做poi自动导出Ecxel表格和Chart折线图的功能. 所以我在网上找到了一篇关于poi生成Chart图表的博客,代码很详细,但是缺少相关注释说明. 想要将它改造成自己需要的样 ...

  3. Android 自动生成的R类

    资源文件的使用分为在代码中使用和在其他资源文件中引用该资源文件.在我们编译一个Android应用时,Android会自动生成一个R类,在该类中根据不同的资源类型又生成了相应的内部类,该类包含了系统中使 ...

  4. 结队编程第二次作业:Android自动生成算式应用

    一.题目要求 本次作业要求两个人合作完成,驾驶员和导航员角色自定,鼓励大家在工作期间角色随时互换,这里会布置两个题目,请各组成员根据自己的爱好任选一题. 这次我和我的小伙伴选择了题目一. 题目1: 实 ...

  5. Android 自动生成表格

    Layout.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:a ...

  6. 自己写的自动生成动态边框的jquery小插件

    思路就是在元素四周添加<ul>列表,然后周期性地改变它的颜色,实现动态的效果,不支持ie7.ie8 预览链接http://gorey.sinaapp.com/myBorder/border ...

  7. android 自动生成jni C语言头文件

    1. 在类里面申明 public native xxx(); 函数接口2. 在安卓工程src目录下 使用命令 javah 包名.类名 生成该类所申明的c语言接口

  8. jmeter自动生成报告

    从JMeter 3.0开始已支持自动生成动态报告,我们可以更容易根据生成的报告来完成我们的性能测试报告. 如何生成html测试报告 如果未生成结果文件(.jtl),可运行如下命令生成报告: jmete ...

  9. Jmeter系列-自动生成html报告

    从JMeter 3.0开始已支持自动生成动态报告,我们可以更容易根据生成的报告来完成我们的性能测试报告. 如何生成html测试报告 如果未生成结果文件(.jtl),可运行如下命令生成报告: jmete ...

随机推荐

  1. 线程间同步之 semaphore(信号量)

    原文地址:http://www.cnblogs.com/yuqilin/archive/2011/10/16/2214429.html semaphore 可用于进程间同步也可用于同一个进程间的线程同 ...

  2. Oracle分页查询与RowNum

    1. RowNum伪列 Oracle中,RowNum是一个伪列,表示当前记录是查询结果集中的第几条. RowNum在使用上应该注意,不能在where条件中用RowNum大于.大于等于.等于某个大于1的 ...

  3. ObjectContext

    ObjectContext 类 提供用于查询和使用对象形式的实体数据的功能.它封装了与数据库的底层连接,使你能执行对象查询. ObjectContext封装 .NET Framework 和数据库之间 ...

  4. javascript对链接进行动态处理化

    // $(function(){// var aLink=$('.nav-content .nav li a'); // 选中所有a// var aText=['在线搭配','星网学院','推客联盟' ...

  5. 论文摘抄 - FlumeJava

    本摘抄不保证论文完整性和理解准确性  原始的MapReduce.分Map,Shuffle,Reduce. Map里包含shards. Shuffle理解为groupByKey的事情.Reduce里包含 ...

  6. ASCII码表及键盘码表。

             ASCII码表 ASCII值 控制字符 ASCII值 控制字符 ASCII值 控制字符 ASCII值 控制字符 0 NUT 32 (space) 64 @ 96 . 1 SOH 33 ...

  7. setTimeout()的返回值

    今天遇到一个问题,题目如下: var len=4; while(len--){ setTimeout(function(){ console.log(len); },0); console.log(l ...

  8. 更改Zend Studio/Eclipse代码风格主题

    最近决定把几个IDE的代码样式统一一下,Visual Studio的还算好改,PHP目前用得不多,不过也打算给Zend Studio换身新装. 网上搜索的一些更改Zend Studio主题的多是修改或 ...

  9. SVN经常使用命令说明

    SVN版本号:1.5 及更新版本号 名词说明: WC:Working Copy 你的工作区 Versioned:受控的:受版本号控制的 SVN是什么? SVN是开源的版本号控制系统. 比CVS很多其它 ...

  10. hdu3368之DFS

    Reversi Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Su ...