Android 自动生成表格
Layout.xml
<?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>
Activity.java
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 自动生成表格的更多相关文章
- ANDROID 自动生成动态表格for
简单的栗子去了解这个自动生成的动态的控件(自动生成表格) /cs-Layout/res/layout/activity_main.xml <LinearLayout xmlns:android= ...
- Android 自动生成的R类
资源文件的使用分为在代码中使用和在其他资源文件中引用该资源文件.在我们编译一个Android应用时,Android会自动生成一个R类,在该类中根据不同的资源类型又生成了相应的内部类,该类包含了系统中使 ...
- 结队编程第二次作业:Android自动生成算式应用
一.题目要求 本次作业要求两个人合作完成,驾驶员和导航员角色自定,鼓励大家在工作期间角色随时互换,这里会布置两个题目,请各组成员根据自己的爱好任选一题. 这次我和我的小伙伴选择了题目一. 题目1: 实 ...
- android 自动生成jni C语言头文件
1. 在类里面申明 public native xxx(); 函数接口2. 在安卓工程src目录下 使用命令 javah 包名.类名 生成该类所申明的c语言接口
- hibnet 自动生成表格
在pom文件中添加相关的依赖 在application.yml文件中添加配置信息 新建实体类Boy 项目运行,mysql就产生了一个boy表. 需要注意的是:当配置文件ddl-auto: create ...
- android_demo之自动生成动态表格
今天我们学习了如何更好的利用Android 的 layout 布局. 接下来是个简单的栗子去了解这个自动生成的动态的控件(自动生成表格) 这是我们的layout 页面 <?xml version ...
- eclipse下Android无法自动生成apk文件怎么办?
eclipse下Android无法自动生成apk文件怎么办? 现象:创建android工程后,通过手动build/clean或自动build均无法在bin文件夹下生成.apk文件 解决方法:进入win ...
- eclipse android 不会自动生成R.java文件和包的解决办法
eclipse下编写android程序突然不会自动生成R.java文件和包的解决办法 我的eclipse原来是好好的,什么问题都没有的,结果今天一打开新建一个android程序,发现工程里不会自动 ...
- 不自动生成Android Dependencies的解决方式
今天遇到的奇怪问题是网上下载的demo导入第三方包运行后Android: NoClassDefFoundError的错误,原因是第三方的jar包并没有打包进apk里,运行是肯定要出错的. 网上百度了N ...
随机推荐
- em
macro jumptocaller(){ JumpToLocation(GetSymbolLocation((GetCurSymbol ())))}
- Asp.Net在多线程环境下的状态存储问题
在应用开发中,我们经常需要设置一些上下文(Context)信息,这些上下文信息一般基于当前的会话(Session),比如当前登录用户的个人信息:或者基于当前方法调用栈,比如在同一个调用中涉及的多个层次 ...
- Date类型,Boolean类型,Number类型
1.Date类型: 1)创建Date对象: var date=new Date(); //Date对象会把当前日期和时间保存为其初始值 2)Date对象的方法: --这些得到的都是数字 ...
- linux centos 6.5 运行MySQL Workbench 6.0找不到 libmysqlclient.so.16和libmysqlclient_r.so.16
找到已安装mysql/lib目录下有类似文件: -rw-r--r-- root root 12月 : libmysqlclient.a lrwxrwxrwx root root 12月 : libmy ...
- OpenCV安装配置的简单记录
在ubuntu16.04下安装OpenCV 2.4.11的简单记录 1. 安装cmake,执行$apt-get install cmake即可,cmake -version验证 2. 下载OpenCV ...
- 【Nginx】配置Nginx的负载均衡
参考的优秀文章 tomcat配置文件server.xml详解 AJP协议总结与分析 Using nginx as HTTP load balancer 在本机运行2个Tomcat 现需要运行两个Tom ...
- 欧姆龙PLC---FINS/TCP
ETN 21 以太网fins/tcp命令 (1)将电脑和PLC设置为同一个网段 例如电脑IP为192.168.18.214,PLC的IP为192.168.18.4(PLC的端口默认为9600) (2) ...
- [转](五)unity4.6Ugui中文教程文档-------概要-UGUI Interaction Components
大家好,我是孙广东. 转载请注明出处:http://write.blog.csdn.net/postedit/38922399 更全的内容请看我的游戏蛮牛地址:http://www.unityma ...
- KNN算法与Kd树
最近邻法和k-近邻法 下面图片中只有三种豆,有三个豆是未知的种类,如何判定他们的种类? 提供一种思路,即:未知的豆离哪种豆最近就认为未知豆和该豆是同一种类.由此,我们引出最近邻算法的定义:为了判定未知 ...
- tcp/ip详解-ip头部选项字段
IP头部的选项字段 作用:用于网络调试和测试 IP首部的可变部分就是一个可选字段.选项字段用来支持排错.测量以及安全等措施,内容很丰富.此字段的长度可变,从1个字节到40个字节不等,取决于所选择的项目 ...