在Android中使用后台代码创建表布局并添加行 [英] Creating table layout and adding rows from the code behind in Android

查看:131
本文介绍了在Android中使用后台代码创建表布局并添加行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个表布局,并从后面的Java代码中动态添加行.我已经在这里阅读了问题,但是他们提到要在已经创建的表布局(从xml)中添加表行.

I need to create a table layout and add rows dynamically from Java code behind. I have already read questions here, but they are mentioning to add table rows in an already created table layout (from xml).

我需要创建表布局以及向其动态添加数据. 有人可以提供一些输入吗?

I need to create the table layout as well as add data to it dynamically. Can anyone please provide some inputs?

现在,我有线性布局代码,该代码从一个代码中的另一个后面添加了按钮,现在我需要将其放置在表格格式中.

For now, I have linear layout code in place which adds button from code behind one below the other, I need to place it under a tabular format now.

推荐答案

要在TableRow中添加三个按钮,请使用下面的代码

To add three buttons to TableRow use the code below

TableLayout tableLayout = new TableLayout(this);
    for (int i = 0; i < 10; i++)
    {
        TableRow tableRow = new TableRow(this);
        Button button = new Button(this);
        button.setText("1");
        tableRow.addView(button);

        button = new Button(this);
        button.setText("2");
        tableRow.addView(button);

        button = new Button(this);
        button.setText("3");
        tableRow.addView(button);

        tableLayout.addView(tableRow);
    }
    setContentView(tableLayout);

这篇关于在Android中使用后台代码创建表布局并添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆