public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* Find Tablelayout defined in main.xml */
TableLayout tl = (TableLayout) findViewById(R.id.store_table);
/* Create a new row to be added. */
for (int i = 0; i < 3; i++) {
TableRow tr = new TableRow(this);
tr.setLayoutParams(new
LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
/* Create a Button to be the row-content. */
Button b = new Button(this);
b.setText("Dynamic Button");
b.setLayoutParams(new
LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
/* Add Button to row. */
tr.addView(b);
Button c = new Button(this);
c.setText("Dynamic Button2");
c.setLayoutParams(new
LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
/* Add Button to row. */
tr.addView(c);
/* Add row to TableLayout. */
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
}
}
'Programming > Android' 카테고리의 다른 글
안드로이드 APK 추출하기 (0) | 2013.04.25 |
---|---|
Thread 와 Handler 테스트 (0) | 2013.04.13 |
TabActivity 사용법 (0) | 2013.03.23 |
다중 액티비티 예제 (0) | 2013.03.23 |
안드로이드 레이아웃 예제 (0) | 2013.03.16 |