2011-03-04 65 views
0

我想在表格佈局中顯示一個字符串數組。有以下code.I能夠獲取數據到日誌文件,但我沒有看到表格佈局。TableLayout相關問題

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)); 

    } 
+0

我們會需要你的佈局XML ... – 2011-03-04 17:22:19

+0

我只是交它。 – PiyushMishra 2011-03-04 17:34:17

+0

得到了問題,但無法解決它。每當我將setText的值更改爲某些靜態文本時,它可以正常工作,但事情發生在我的日誌中,我可以看到值[current]正常工作,但在表格佈局中無效。 – PiyushMishra 2011-03-04 17:59:04

回答

0

我知道這很長時間後,但它可以幫助你或其他人。 在其中創建該行並添加布局PARAMS它,使用以下類型則params的

TableRow.LayoutParams NOT的TableLayout.LayoutParams