본문 바로가기

프로그램/ANDROID

java android tablelayout /안드로이드 자바에서 화면으로 값전달

반응형

java android tablelayout /안드로이드 자바에서 화면으로 값전달

 

 

안드로이드 자바소스에서 만든 테이블 디자인으로 화면으로 전달하는 방법

 

 

자바에서 동적으로 table을 그려서 화면으로 보여주는 방법입니다.

 

 

화면 game.xml

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<Button
android:id="@+id/confButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="32dp"
android:text="@string/confirm_button"
tools:context=".GameActivity" />

<TableLayout
android:id="@+id/table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:stretchColumns="*">

</TableLayout>

</RelativeLayout>

 

---------------------------------------

자바소스 입니다.

 

 

public class GameActivity extends Activity implements OnClickListener

{

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

super.onCreate(savedInstanceState);
setContentView(R.layout.game); //화면 이름
final TableLayout tableLayout = (TableLayout) findViewById(R.id.table); // 테이블 id 명

for (int i = 0; i < 9; i++) {
// Creation row
final TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));


for(int j = 0 ; j < 9 ; j++){
final TextView text = new TextView(this);

text.setText( i + j + "|");
text.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));

tableRow.addView(text);
}

tableLayout.addView(tableRow);
}


}


public void onClick(View arg0) {

// TODO Auto-generated method stub

// String path = getFilesDir().getAbsolutePath();

Intent intent = null;

switch (arg0.getId()) {

}

 

}


}

 

 

 

 

반응형