TableLayout相关问题

时间:2011-03-04 17:18:38

标签: android

我想在表格布局中显示一个字符串数组。有以下代码。我能够将数据存入日志文件,但表布局我什么也看不到。

TableLayout tl=(TableLayout)findViewById(R.id.maintable);
     for(int current=0;current<cursor1.getCount();current++)
     {
         //create a table row
     TableRow tr=new TableRow(this);
     tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
     // create a text view for start time
     TextView sTime= new TextView(this);
     sTime.setText(values[current]);
     sTime.setTextColor(Color.YELLOW);
     Log.i("Data Check", values[current]);
     sTime.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
     tr.addView(sTime);
     //add the table row into TableLayout
     tl.addView(tr, new TableLayout.LayoutParams(
             LayoutParams.FILL_PARENT,
             LayoutParams.WRAP_CONTENT));

     }

1 个答案:

答案 0 :(得分:0)

我知道这很长时间,但它可能会帮助你或其他人。 在创建行并向其添加布局参数的位置,请使用以下类型的参数

TableRow.LayoutParams不是TableLayout.LayoutParams

相关问题