android动态生成表格,使用的是TABLELAYOUT
来源:互联网 发布:刑法修正案九网络犯罪 编辑:程序博客网 时间:2024/04/29 04:58
使用tablelayout及tablerow生成表格,这里我只生成了一次,可以根据需求更改哦....,对于里面的控件是可以监听的....
mainactivity代码如下:
- package com.xy.tablerow;
- import android.os.Bundle;
- import android.app.Activity;
- import android.graphics.Color;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.ViewGroup.LayoutParams;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ImageView;
- import android.widget.TableLayout;
- import android.widget.TableRow;
- import android.widget.TextView;
- import android.widget.Toast;
- import android.support.v4.app.NavUtils;
- public class MainActivity extends Activity implements OnClickListener {
- Button bu;
- boolean mFlag = false;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Button mButton = (Button) findViewById(R.id.myButton);
- mButton.setOnClickListener(this);
- bu = new Button(MainActivity.this);
- bu.setText("tianjia");
- bu.setId(0x10);
- bu.setOnClickListener(this);
- }
- public void addWegit() {
- TableLayout table = (TableLayout) findViewById(R.id.tablelayout);
- table.setStretchAllColumns(true);
- for (int i = 0; i < 6; i++) {
- TableRow tablerow = new TableRow(MainActivity.this);
- tablerow.setBackgroundColor(Color.rgb(222, 220, 210));
- for (int j = 0; j < 3; j++) {
- if (i == 0 && j == 0) {
- tablerow.addView(bu);
- } else {
- EditText testview = new EditText(MainActivity.this);
- testview.setBackgroundResource(R.drawable.shape);
- // testview.setText("选择");
- tablerow.addView(testview);
- }
- }
- table.addView(tablerow, new TableLayout.LayoutParams(
- LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
- }
- }
- @Override
- public void onClick(View v) {
- int vv = v.getId();
- switch (vv) {
- case 0x10:
- Toast.makeText(MainActivity.this, "heh,keyidianjide",
- Toast.LENGTH_SHORT).show();
- break;
- case R.id.myButton:
- if (!mFlag) {
- addWegit();
- mFlag = !mFlag;
- }
- break;
- }
- }
- }
xml布局如下:
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
- <Button
- android:id="@+id/myButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="动态生成表格" />
- <TableLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="#dedcd2"
- android:stretchColumns="*" >
- <TableRow
- android:layout_margin="0.5dip"
- android:background="#dedcd2" >
- <TextView
- android:background="#ffffff"
- android:gravity="center"
- android:text="年度"
- android:textSize="20dip"
- android:textStyle="bold" />
- <TextView
- android:gravity="center"
- android:background="#ffffff"
- android:text="本金"
- android:textSize="20dip"
- android:textStyle="bold" />
- <TextView
- android:gravity="center"
- android:background="#ffffff"
- android:text="利息"
- android:textSize="20dip"
- android:textStyle="bold" />
- </TableRow>
- </TableLayout>
- <TableLayout
- android:id="@+id/tablelayout"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="#dedcd2"
- android:stretchColumns="*" >
- <TableRow
- android:layout_margin="0.5dip"
- android:background="#dedcd2" >
- <TextView
- android:layout_margin="1dip"
- android:background="#ffffff"
- android:text=""
- android:textSize="20dip"
- android:textStyle="bold" />
- <TextView
- android:layout_margin="1dip"
- android:background="#ffffff"
- android:text=""
- android:textSize="20dip"
- android:textStyle="bold" />
- <TextView
- android:layout_margin="1dip"
- android:background="#ffffff"
- android:text=""
- android:textSize="20dip"
- android:textStyle="bold" />
- </TableRow>
- </TableLayout>
- </LinearLayout>
- 效果图如下:
- 顶
- 1
- 踩
- 1
0 0
- android动态生成表格,使用的是TABLELAYOUT
- Android 动态生成表格,使用的是TABLELAYOUT并排序
- android动态生成表格,使用的是TABLELAYOUT
- android动态生成表格,使用的是TABLELAYOUT
- android动态生成表格,使用的是TABLELAYOUT
- Android开发-使用TableLayout动态显示表格
- Android开发-使用TableLayout动态显示表格
- android表格布局TableLayout的使用
- android学习——使用TableLayout动态生成表格,并为tablerow中的列添加点击监听
- android学习——使用TableLayout动态生成表格,并为tablerow中的列添加点击监听
- android 使用TableLayout 绘制表格
- TableLayout表格简单的使用
- TableLayout 动态表格
- Android TableLayout(表格布局) 使用介绍
- Android TableLayout的使用
- 表格布局(TableLayout)的简单使用
- TableLayout的使用来制作表格
- android-TableLayout 表格布局
- SAS 9.4 背景颜色、护眼色 设置
- java面试题--java基础--迈达斯篇
- 比较排序之插入和归并排序
- 第三周 项目4-顺序表的应用(1)
- Android中常见的内存泄漏
- android动态生成表格,使用的是TABLELAYOUT
- AngularJS内置指令之基础ng指令
- JavaScript对象的浅拷贝和深拷贝简单实现
- zookeeper学习准备知识
- left 外连
- Double型数据的精度问题
- Android 一些面试问题收集
- Android开发:LayoutParams的用法
- 时钟五:用串口发送时间,实现闹钟