다른 ID (Java 파일의 로컬 변수 - 코드 참조)가있는 두 행의 TextView가있는 동적 테이블 행을 만들었습니다. TextView의 ID와 동일한 ID를 사용하여 다른 액티비티를 열고 싶습니다. (의도를 사용하여 보낼 수 있습니다)테이블 레이아웃의 TextViews onClickListener에 동적 데이터 추가
하지만 먼저 TextView에 할당 된 동일한 ID로 토스트를 인쇄하려고했습니다. XML 코드
// Java Code
int id = 3;
for (int i = 1; i <= 3; i++) {
TableRow row = new TableRow(TableActivity.this);
// add Layouts to your new row
TextView txt1 = new TextView(TableActivity.this);
txt1.setText("" + id);
txt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "" + id,
Toast.LENGTH_SHORT).show();
}
});
id++;
TextView txt2 = new TextView(TableActivity.this);
txt2.setText("" + id);
id++;
row.addView(txt1);
row.addView(txt2);
// add your new row to the TableLayout:
TableLayout table = (TableLayout) findViewById(R.id.tableLayout1);
table.addView(row);
}
,
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:stretchColumns="0,1,2,3"
tools:context="com.himanshu.fileimage.TableActivity" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Column1"
android:textColor="#000000" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Column2"
android:textColor="#000000" />
</TableRow>
오류가 내부 클래스 내부로 ID가 최종 변수되어야한다는 토스트 붙어
.
내 문제의 가능한 해결책은 무엇입니까?
u가없는 목록보기 –
@NaveenTamrakar Why ListView? –
런타임에 데이터를 추가하려는 경우 런타임에 listview에 데이터를 추가했습니다. –