【问题标题】:create multiple runtime textview in android在android中创建多个运行时textview
【发布时间】:2015-10-01 01:36:17
【问题描述】:

我在 Eclipse 中有用于在多行中创建多个 TextView 的代码,但是运行时应用程序项目不显示,请帮助我如何修复它。

这是我的代码:

public void createInputBoxes(Activity gameplay, int colnums, int rownums, TableLayout.LayoutParams lparams, TableLayout puzzlelayout) {

    TextView[][] puzcels = new TextView[colnums][];
    puzzlelayout.removeAllViews();

    for(int c=0; c<colnums; c++)
    {
        puzcels[c]=new TextView[rownums];
        TableRow tr = new TableRow(gameplay);
        tr.setLayoutParams(lparams);

        for(int r=0; r<rownums; r++)
        {
            puzcels[c][r] = new TextView(gameplay);
            puzcels[c][r].setLayoutParams( lparams);
            puzcels[c][r].setId(tvid);
            puzcels[c][r].setText("?");
            tvid++;
            puzcels[c][r].setBackgroundColor(0xffffb90f);
            tr.addView(puzcels[c][r]);

        }
        puzzlelayout.addView(tr,lparams);
    }
}

【问题讨论】:

    标签: android eclipse textview runtime tablerow


    【解决方案1】:

    您正在为所有视图使用 TableLayout.LayoutParams 参数 - TableLayoutTableRowTextView。这对最后两个不起作用。您需要为他们提供适合他们的参数:

    Dynamically filling a Table Layout with Table Rows

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-27
      • 1970-01-01
      • 1970-01-01
      • 2017-04-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多