エントリの場合、リストとして表示されるデータを取得するために Web サービスを使用しています。XML ファイルに 2X2 テーブル レイアウト形式の 4 つの属性があります。次に、Java コードで TableLayout クラスを使用して、結果を各 TableRow に格納します。
これが私のxmlコードです: tabrow.xml
<?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 コードを次に示します。
<TableLayout
android:id="@+id/resultDetail"
android:layout_width="fill_parent"
style="@style/BodyRow"
android:layout_height="wrap_content" >
</TableLayout>
以下はJavaコードです。
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());
}
}
以前は、4 つのエントリすべてを 1 つずつ取得するために繰り返し呼び出した xml ファイルに「tablerow」しかないときに機能していました。しかし、画面スペースを節約するために、2行の「tableyalout」を挿入しようとしましたが、機能しなくなりました。ここで何が間違っていますか?どんな助けでも大歓迎です。