Android 自动生成表格

摘要:
Layout.xml˂?xmlversion="1.0"encoding="utf-8"?

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

importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.TableLayout;
importandroid.widget.TableRow;

public class MainActivity extends Activity implementsOnClickListener {

    privateButton submit;
    privateEditText row;
    privateEditText cloumn;
    privateTableLayout table;

    @Override
    protected voidonCreate(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 voidonClick(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 自动生成表格第1张

时人不识凌云木,直待凌云始道高

免责声明:文章转载自《Android 自动生成表格》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇【语义分割】3D Graph Neural Networks for RGBD Semantic SegmentationJmeter脚本增强之参数化(多方式实现)(6)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Python 开发安卓Android及IOS应用库Kivy安装尝试

Python 开发安卓Android及IOS应用库Kivy安装尝试: 先来看看这货可以用来制作什么应用: Create a package for Windows Create a package for Android Creating packages for OS X Create a package for IOS 逆天的节奏啊,虽然600+页...

三 APPIUM Android自动化 测试初体验

1.创建一个maven项目 成功新建工程: 编辑pom.xml,在<dependencies></dependencies>下添加appium相关依赖: <dependency> <groupId>org.testng</groupId> <artifactId>...

安卓app设计规范整理和Android APP设计篇(转)

随着安卓智能手机不停的更新换代。安卓手机系统越来越完美,屏幕尺寸也越来越大啦!比如最近小米的miui 6的发布和魅族手机系统的更新等等。 以小米MIUI6的安卓手机来说,MIUI6进行了全新设计,坚持“内容才是本质”的设计哲学,重新提炼内容,简化图标设计。 所以,我们在进行安卓APP设计时,需要好好调整之前的设计规范和设计细节。根据目前流行的安卓手机的系...

Unity 登录注册功能的实现(PlayerPrefs)

1、首先了解下 Unity 的 PlayerPrefs 存储 目前,在 Unity 中只支持 int、string、float 三种数据类型的读取,所以我们可以使用这三种数据类型来存储简单的数据 而其中用于数据持久化的类为 PlayerPrefs,如下: 数据保存 PlayerPrefs.SetString(“Name”,Key.value); Play...

layer第二个按钮点击后关闭的解决方法

在使用layer的时候,第二个按钮事件尚未执行完毕,它会自动关闭,效果很不好,网上找了一种解决办法,就是return false;在第二个按钮的回调函数里面加上就可以了   btn2: function (index, layero) {//不通过审核visitor.UpdateAuditInfo(RESERVATIONID, 2);//保存访客信息采集...

angular 使用bootstratp模态框+响应式表单+响应式表单的验证+子窗关闭父窗口刷新

This is quite big project today 这次有以下几个功能: 1.ng-bootstrap模态框 2.响应式表单 3.响应式表单的验证  4.子窗关闭父窗口刷新 其实这几个哪一个都能写一个话题,事情太多了,时间紧任务重,一起写了吧: ng-bootstrap模态框所需要的条件(very very important),如果写错,查错...