2011-08-04 6 views
0

J'ai arraylist des objets et j'ai besoin de lier ces objets à la liste des TableLayout lors de l'exécution, mais je n'ai pas de données en elle, s'il vous plaît vérifier mon code:Problème de liaison TableLayout lors de l'exécution?

code XML:

<TableLayout android:background="#cfe1edFF" android:id="@+id/tl" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 

    <TableRow> 
    <TextView android:text="Symbol" 
    android:layout_height="fill_parent" android:textColor="#104e8b" 
     android:layout_width="wrap_content" 
     android:layout_weight="1" android:gravity="center" android:background="@drawable/shapefile"/> 
    <TextView android:text="A/c Type" 
    android:layout_height="fill_parent" android:textColor="#104e8b" 
     android:layout_width="wrap_content" 
     android:layout_weight="1" android:gravity="center" android:background="@drawable/shapefile"> 
    </TextView> 
    <TextView android:text="Position" android:textColor="#104e8b" android:layout_height="fill_parent" 
     android:layout_width="wrap_content" 
     android:layout_weight="1" android:gravity="center" android:background="@drawable/shapefile"> 
    </TextView> 
    </TableRow> 

    <ScrollView>  
    <TableLayout android:id="@+id/score_table" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
     <TableRow></TableRow>   
    </TableLayout> 
    </ScrollView>  
</TableLayout> 

donc d'en haut TableLayout "score_table" je suis en train de lier des données à partir ArrayList d'objets tels que:

code pour lier la mise en page de table à l'aide d'objets arryalist:

public void TableBinding(ArrayList<Position> posLst) 
    { 
     TableLayout tLayout=(TableLayout)findViewById(R.id.score_table); 
     Position pos; 
     for(int i=0;i<posLst.size();i++) 
     { 
      TableRow tr = new TableRow(this); 
      tr.setId(100+i); 
      pos=posLst.get(i); 
      tr.setLayoutParams(new LayoutParams(
         LayoutParams.FILL_PARENT, 
         LayoutParams.WRAP_CONTENT)); 


      TextView b = new TextView(this); 
      b.setText(pos.Symbol); 
      tr.addView(b); 
      //b.setId(200+i); 

      TextView b1 = new TextView(this); 
      b1.setText(pos.AcType); 
      tr.addView(b1); 
      //b1.setId(300+i); 

      TextView b2 = new TextView(this); 
      b2.setText(pos.Position); 
      tr.addView(b2); 
      //b2.setId(400+i); 



      /* Add row to TableLayout. */ 
      tLayout.addView(tr,new TableLayout.LayoutParams(
        LayoutParams.FILL_PARENT, 
        LayoutParams.WRAP_CONTENT)); 

     } 

    } 

Mais je n'ai pas reçu de données, j'ai déjà vérifié que ArrayList obtenait des données, aidez-moi s'il vous plaît.

Merci, nag.

Répondre

1

Vous essayez de cette façon:

ArrayList<String> tablesName = new ArrayList<String>(); 
TableLayout tl; 

public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 

    tl = (TableLayout) findViewById(R.id.tableLayout1); 

    for (int i = 0; i < posLst.size(); i++) { 
    TableRow tr = new TableRow(this); 
    CheckBox ch = new CheckBox(this); 
    ch.setId(i); 

    TextView tv2 = new TextView(this); 
    tr.addView(ch); 
    createView(tr, tv2, tablesName.get(i)); 
    tl.addView(tr); 
} 

    public void createView(TableRow tr, TextView t, String viewdata) { 
    t.setText(viewdata); 
    t.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
    t.setTextColor(Color.DKGRAY); 
    t.setPadding(20, 0, 0, 0); 
    tr.setPadding(0, 1, 0, 1); 
    tr.addView(t); 
} 
+0

encore je ne l'ai pas obtenir – nag

+0

:(puis-je poster mon code après que les modifications – nag

+0

yes.You peut? collez-le ici http://pastebin.com/ & donnez-moi le lien – Piraba

0

essayer ça a marché pour moi

for (int position=0; position < data.size(); position++) 
      { 
       TableRow tableRow= new TableRow(this); 

       ArrayList<Object> row = data.get(position); 

       TextView idText = new TextView(this); 
       idText.setText(pos.Symbol); 
       tableRow.addView(idText); 

       TextView textOne = new TextView(this); 
       textOne.setText(pos.AcType); 
       tableRow.addView(textOne); 

       TextView textTwo = new TextView(this); 
       textTwo.setText(pos.AcType); 
       tableRow.addView(textTwo); 

       dataTable.addView(tableRow);  
      } 
     } 
+0

ya que j'ai essayé comme ça aussi mais ne pas obtenir – nag