2012-01-12 6 views
0

私は9行のテーブルレイアウトを持っています。最初のものは見出しのためのものです。列の数は変わります。だから私は動的にテーブルの行にtextviewを追加する必要があります。 Iamはテーブル行を膨張させ、固定されている最初の列のテキストを追加します。他のクーミンはループでそれを追加しようとしています。しかし、私は最初の細胞だけを取得しています。タブローに列を動的に追加します。ループ内にテキストビューを追加する。 settext not working

col# A B C D E F 
---------------------------- 
1  65 6 6 5 6 7 
---------------------------- 
2  6 4 7 4 6 8 

列の何が3〜6にすることができますが、行は、私はこのような入れ抜け出す8

です:

私のうち予想プットは次のようではありません

col# 
    ---------------------------- 
    1 
    ---------------------------- 
    2 

iamが最初の行を表示しようとしています。しかし、私は最初の細胞だけを取得しています。誰でも助けることができますか?

テーブル行

<?xml version="1.0" encoding="utf-8"?> 

    <TableRow xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> 
     <TextView android:id="@+id/sn4" 
        android:textSize="25sp" 
        android:layout_marginTop="15dip" 
        android:layout_marginLeft="20dip" 
        style="@style/normalText" 
        android:textColor="@color/title" 
      /> 



</TableRow> 

と私のXML私は私のコードで

<?xml version="1.0" encoding="utf-8"?> 


    <TextView xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/txtfactor" 
       android:textSize="25sp" 
       android:layout_marginTop="15dip" 
       android:layout_marginLeft="20dip" 
       style="@style/normalText" 
       android:textColor="@color/title" 
     /> 

のTextViewのための別のXML有する:

TBL =(TableLayout)findViewById(R.idを。 tbltrail); for(int i = 0; i < = noOfTrials; i ++){ TableRow child =(TableRow)getLayoutInflater()。inflate(R.layout.trial_table、null); child.setId(i); TextView sno =(TextView)child.findViewById(R.id.sn4); if(i == 0){ sno.setText( "Col#");このため

  for(int j=0; j<count; j++){ 
       FactorObj factorObj = factorList.get(i); 
       View row = (View) getLayoutInflater().inflate(R.layout.trial_row_content, null); 
       TextView factorname = (TextView)row.findViewById(R.id.txtfactor); 
       factorname.setId(200+j); 
       Log.v(null, "factor name "+factorObj.getFactorName()); 
       factorname.setText("sdf"); 
       child.addView(row); 



      } 
      tbl.addView(child); 


     }else{ 
      sno.setText(String.valueOf(i)); 
      for(int j=0; j<count; j++){ 
       FactorObj factorObj = factorList.get(i); 
       View row = (View) 

       getLayoutInflater().inflate(R.layout.trial_row_content, null); 
       TextView factorname = (TextView)row.findViewById(R.id.txtfactor); 
       factorname.setId(100+j); 
       factorname.setText("ss"); 
       child.addView(row); 


      } 
      tbl.addView(child); 
     } 

    } 
+0

.....ちょうどそれをグーグルのViewGroupについて知らない場合は、行へのp

mRow.addView(mCell); 

は、テーブルレイアウト

mTableLayout.addView(mRow); 

に追加しますか? '行'は使用されません。代わりに、その一部がコンテナに追加されます。 IMOはきれいではありません。 – Deucalion

+0

申し訳ありませんコードを編集しました。各テーブル行で私はシリアル番号を記入するために固定されたテキストビューを保持しています。他のテキストビューはレイアウトから動的に生成され、このテーブルレイアウトに追加されます。私はそれを正しくやっているかどうかわかりません。 – AD14

答えて

6

mCell = new CellViewGroup(this,parameters); 

のビューグループを作成し、 XML

mTableLayout = (TableLayout) findViewById(R.id.mytable); 

からテーブルレイアウトを参照の動的

TableRow mRow = new TableRow(this); 

追加テーブルの行を作成しますグルグを見るあなたはaddViewビューをreparents

+0

私はこれを別のアプリで試しました。ここで私はXMLからtablerowを膨らませようとしています。ループ内に表示するときに使用します。 setTextは機能しません。とりあえずありがとう。 – AD14

関連する問題