2014-12-06 3 views
0

데이터를 테이블에 삽입하여 매우 간단한 스케줄러를 만들고 싶습니다. 이 정보를 얻는 데 문제가 없지만 의미있는 테이블에 삽입 할 수는 없습니다.테이블에 추가 Android TableLayout

DAY 1 :

DAY 2

DAY 3 : 의미가 테이블에 의해, I 후속 추가가 존중 제목 아래에 삽입과 같은 아웃 시작 테이블 의미

DAY 4 :

나는 사용자로부터 코스 정보를 얻고 자신의 시간표에 발생한 시간을 기준으로 코스를 분류하려고합니다. 나는 이것을 테이블로 조직하는 데 다소 어려움을 겪고있다.

내가 어떻게 효율적으로 정렬할지에 대한 제안 사항은 무엇입니까?

답변

0

TableLayout을 사용하고 XML로 레이아웃 템플릿을 만듭니다. 예를 들어 :

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tableLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="5dp" > 

     <TextView 
      android:id="@+id/textView1" 
      android:text="DAY 1:" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 

    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="5dp" > 

     <TextView 
      android:id="@+id/textView1" 
      android:text="DAY 2:" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 

    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="5dp" > 

     <TextView 
      android:id="@+id/textView1" 
      android:text="DAY 3:" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 

    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="5dp" > 

     <TextView 
      android:id="@+id/textView1" 
      android:text="DAY 4:" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 

    </TableRow> 

</TableLayout> 

는 그런 과정 정보의 목록을 검사하고 모든 과정에 대해 이전에 생성 된 레이아웃에 TableRow로에 대한 프로그래밍 방식으로 정보를 추가 할 수 있습니다. 이를 위해서는 TableLayout#addView(View child, int index)을 사용하십시오. 예 TableLayout에 마지막 행으로 TableRow 포함 TextView를 추가하려면 :

TableLayout tl = (TableLayout) findViewById(R.id.my_table_layout); 
TableRow tr = new TableRow(context); 
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); 
TextView tv = new TextView(context); 
tv.setText("Some text"); 
tv.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); 
tr.addView(tv); 
tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT)); 
+0

이 좋아, 그 의미가 있습니다. 고맙습니다. 테이블을 어떻게 업데이트합니까? – Matthew

+0

'TableRow'를 생성하고'TableLayout # addView' 메소드를 사용하여'TableLayout'에 추가하십시오. 업데이트 된 답변보기 –

관련 문제