如何建立在Android中使用Java code多列的表视图? [英] How to create a multiple column table view in android using java code?

查看:160
本文介绍了如何建立在Android中使用Java code多列的表视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的深化发展Android应用程序。为此,我需要有一个动态的tableView。我使用TableLayout为它可在机器人。但我不能找到一种方法,有多个列在我的tableView。任何选项吗?

I'm developping an android application. For that I need to have a dynamic tableView. I'm using TableLayout for that which is available in android. But I couldn't find a way to have multiple columns in my tableView. Any option please?

推荐答案

我不知道我完全理解你的问题,但在这里:

I don't know if I fully understand your question, but here:

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    TableLayout tableLayout = new TableLayout(getApplicationContext());
    TableRow tableRow;
    TextView textView;

    for (int i = 0; i < 4; i++) {
        tableRow = new TableRow(getApplicationContext());
        for (int j = 0; j < 3; j++) {
            textView = new TextView(getApplicationContext());
            textView.setText("test");
            textView.setPadding(20, 20, 20, 20);
            tableRow.addView(textView);
        }
        tableLayout.addView(tableRow);
    }
    setContentView(tableLayout);
}

这code 3列和第4行创建TableLayout。基本上,你可以有TableLayout在XML文件中声明,那么的setContentView为XML,并使用findViewById找到你TableLayout。只有的TableRow和它的孩子们在Java code来完成。

This code creates TableLayout with 3 columns and 4 rows. Basically you can have TableLayout declared in XML file, then setContentView to XML, and use findViewById to find your TableLayout. Only TableRow and it's children have to be done in java code.

这篇关于如何建立在Android中使用Java code多列的表视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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