항목이있는 경우 웹 서비스를 사용하여 목록으로 표시 할 데이터를 가져옵니다. 내 XML 파일에서 2X2 테이블 레이아웃 형식으로있는 네 가지 특성이 있습니다. 그런 다음 Java 코드에서 TableLayout 클래스를 사용하여 각 TableRow에 결과를 저장합니다.android에서 TableLayout을 사용하여 프로그래밍 방식으로 항목 목록을 표시하는 방법
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableRow2"
style="@style/BodyRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableRow android:id="@+id/tableRow2"
style="@style/BodyRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/attrib_value2"
style="@style/LeftHeaderText"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="TextView"
android:textColor="@color/textColor" />
<TextView
android:id="@+id/attrib_value5"
style="@style/HourText"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="TextView"
android:textColor="@color/textColor" android:gravity="right">
</TextView>
</TableRow>
<TableRow android:id="@+id/tableRow3"
style="@style/BodyRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/attrib_value3"
style="@style/BodyText"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="TextView"
android:textColor="@color/textColor" >
</TextView>
<TextView
android:id="@+id/attrib_value4"
style="@style/BodyText"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="TextView"
android:textColor="@color/textColor" >
</TextView>
</TableRow>
</TableLayout>
가 여기에 tabrow.xml 각 항목을 추가하기 위해 호출되는 내부의 또 다른 XML 코드의 tabrow.xml :
여기 내 XML 코드입니다.
<TableLayout
android:id="@+id/resultDetail"
android:layout_width="fill_parent"
style="@style/BodyRow"
android:layout_height="wrap_content" >
</TableLayout>
다음은 자바 코드입니다.
public void fillWorkEntries(ArrayList<WorkEntry> workEntries) {
try {
TableLayout table = (TableLayout) WorkEntryScreenActivity.this
.findViewById(R.id.resultDetail);
table.removeAllViews();
for (WorkEntry workEntry : workEntries) {
TableLayout nestedtable = (TableLayout) LayoutInflater.from(this).inflate(
R.layout.tabrow, null);
TableRow bodyRow = (TableRow) LayoutInflater.from(this).inflate(
R.id.tableRow2, null);
((TextView) bodyRow.findViewById(R.id.attrib_value2))
.setText(workEntry.getWorkRequestName());
((TextView) bodyRow.findViewById(R.id.attrib_value5))
.setText(workEntry.getActHrs());
TableRow bodyRownext = (TableRow) LayoutInflater.from(this).inflate(
R.id.tableRow3, null);
((TextView) bodyRownext.findViewById(R.id.attrib_value3))
.setText(workEntry.getActivity());
((TextView) bodyRownext.findViewById(R.id.attrib_value4))
.setText(workEntry.getWorkEntryDesc());
table.addView(nestedtable);
}
Log.d(TAG, "Load Entries");
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, e.toString());
}
}
그것은 내가 반복적으로 모두 네 개의 항목을 하나씩 가져 오기 위해 호출 내 XML 파일 만 'tablerow을'있을 때 전에 작동하는 데 사용됩니다. 하지만 일부 화면 공간을 절약하기 위해 두 개의 행으로 'tableyalout'을 삽입하려고 시도했지만 작동을 멈췄습니다. 여기서 내가 뭘 잘못하고 있니? 어떤 도움을 주시면 감사하겠습니다.
TableRow bodyRow = (TableRow) LayoutInflater.from(this).inflate(
R.layout.tabrow, null);
는 캐스트 예외가 발생합니다 : 당신이 그렇게 줄을 캐스팅으로
당신이 팽창 한 중첩 된 테이블 개체의 일부로서, 당신의 행을 팽창 할 필요가 야해. 팽창하려고하면 어떻게 팽창해야하는지 압니까 ??? – trumpetlicks
inflate.layout을 사용하고 findById 메소드를 사용하지 않았으므로 테이블 행 ID를 제공 할 필요가 없습니다. 나는? 내가 어떻게해도 나는 그들을 사용합니까? – Harsh
Im 정직하게 질문에 대해서는 모르겠지만 제공된 코드의 예에서 "R.layout.tabrow"또는 "R.layout.work_seprater"란 무엇입니까? 그 사람들은 어디에서 왔습니까? – trumpetlicks