Search

'TableLayout'에 해당되는 글 1건

  1. 2013.03.23 테이블 동적 생성

테이블 동적 생성

Programming/Android 2013. 3. 23. 20:02 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

 

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