Thursday, November 27, 2008

Building Andoird Table Layout dynamically.

Articles talks about dynamically building your table layout for android.

Code in the Activity:


TableLayout layout = (TableLayout)findViewById(R.id.home_layout);
for(int i=0;i<10;i++){
Log.d("Shipment", "ConsignmentVO:" + vo);
TableRow row = new TableRow(ctx);
TextView shipmentNo = new TextView(ctx);
shipmentNo.setText(i);
row.addView(shipmentNo);
TextView shipmentName = new TextView(ctx);
shipmentName.setText("name"+i);
row.addView(shipmentName);
Button button = new Button(ctx);
button.setText(vo.getId());
row.addView(button);
layout.addView(row);
}

}

Layout xml: xml

No comments: