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

/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. Google 2013 campus test-R1

    Reading Phone Number #include<iostream> #include<fstream> #include<vector> #includ ...

  2. awk--动作(action)

    摘要 在awk--简述中我们讲到awk是由pattern-action组合而成的,关于pattern我们已经awk--模式(pattern)在讲述,接下来就来看下awk的action. 动作是什么 我 ...

  3. Oracle&#39;s Business Intelligence Applications Configuration Manager 基本概念

    Oracle's Business Intelligence Applications Configuration Manager :BIACM Once the BIAPPS installatio ...

  4. PHP5.4新特性(转)

    PHP5.4正式前两天发布了,之前有看了一些PHP5.4主要特性相关文章,因此在这里小结一下. 其中好几点更新是由Laruence贡献的!本文部分内容也是源自Laruence的博客. 1. Buid- ...

  5. Java基础知识强化81:Math类random()方法之获取任意范围的随机数案例(面试题)

    1. 需求:设计一个方法,可以实现获取任意范围内的随机数 分析:使用方法random()如下: public static double random() 注:Returns a pseudo-ran ...

  6. jquery实现图片切换和js实现图片切换

    jquery实现图片切换: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http ...

  7. HDU -2670 Girl Love Value

    这道题是刚好装满的背包问题,刚好选取k个,状态转移方程为dp[i][j] = max( dp[i - 1][j], dp[i - 1][j - 1] + Li - Bi(j - 1) ) dp[i][ ...

  8. linux的comm命令

    http://blog.csdn.net/apache6/article/details/5789669

  9. 《CSS网站布局实录》学习笔记(三)

    第三章 CSS网页布局与定位 3.1 div 几乎XHTML中的任何标签都可以用于浮动与定位,而div首当其冲.对于其他标签而言,往往有它自身存在的目的,而div元素存在的目的就是为了浮动与定位. 3 ...

  10. Design Pattern ——Builder

    一.基础知识:先前学习建造者模式的时候,总是以这个UML图作为学习基础资料 然后总是要记住四个角色 产品类:一般是一个较为复杂的对象,也就是说创建对象的过程比较复杂,一般会有比较多的代码量.在本类图中 ...