【问题标题】:Array of TableRows in table layout表格布局中的 TableRows 数组
【发布时间】:2014-02-21 19:39:28
【问题描述】:

是否可以这样使用TableRow:

那是 TableRows 的数组。这必须在表格布局内,其中表格布局嵌套在线性布局内。

TableRow[] tr = new TableRow[dimension];

【问题讨论】:

    标签: android


    【解决方案1】:

    是的...这在 Android 中是绝对可能的。 TableRow 是一个类,您正在尝试创建一个类的对象数组。

    【讨论】:

    • TextView 可以使用二维数组吗
    • 是... TextView 的二维数组是可能的... 例如:TextView textView[][] = new TextView[2][2];
    【解决方案2】:

    是的,绝对有可能。检查this 链接并尝试此代码。

    public void init(){
    TableLayout ll = (TableLayout) findViewById(R.id.displayLinear);
    
    
    for (int i = 0; i <2; i++) {
    
        TableRow row= new TableRow(this);
        TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
        row.setLayoutParams(lp);
        checkBox = new CheckBox(this);
        tv = new TextView(this);
        addBtn = new ImageButton(this);
        addBtn.setImageResource(R.drawable.add);
        minusBtn = new ImageButton(this);
        minusBtn.setImageResource(R.drawable.minus);
        qty = new TextView(this);
        checkBox.setText("hello");
        qty.setText("10");
        row.addView(checkBox);
        row.addView(minusBtn);
        row.addView(qty);
        row.addView(addBtn);
        ll.addView(row,i);
    }}
    

    检查 Fredigato 在该链接中发布的答案。希望这会有所帮助。

    【讨论】:

    • 多维可能
    • 多维对于具有 TABLE ROW 的 TABLE LAYOUT 意味着什么?从上面的代码中,您可以在 TABLE LAYOUT 中添加 TABLEROW 的动态数量,但我没有得到 TABLELAYOUT 的多维字。
    猜你喜欢
    • 1970-01-01
    • 2023-03-05
    • 2015-02-04
    • 1970-01-01
    • 1970-01-01
    • 2011-10-28
    • 2013-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多