次の図に示すように、いくつかの静的ヘッダーを持つ ListView を作成しています。
ヘッダー列 (日付、ステータス、緯度、経度) の幅を、対応する列の幅に合わせて調整したいと考えています。
私がしようとしているのは、アダプターに関連付けられたリスト項目のレイアウトを取得して、ListActivity でその子の幅を見つけることができるようにすることです (しかし、それは不可能のようです)。
次に、次のコードに示すように、カスタム ArrayAdapter の getView メソッドで、リスト項目に関連付けられた各 TextView の幅を取得しようとしました (ただし、null が返されます。textView を再レンダリングする前に幅を返すことはできないと思います)。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
DispatchHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new DispatchHolder();
holder.tvcurrentDateTime = (TextView) row
.findViewById(R.id.tvCurrentDateTimeLog);
holder.tvAction = (TextView) row.findViewById(R.id.tvActionLog);
holder.tvLatitude = (TextView) row.findViewById(R.id.tvlatitudeLog);
holder.tvLongitude = (TextView) row
.findViewById(R.id.tvlogitudeLog);
row.setTag(holder);
} else {
holder = (DispatchHolder) row.getTag();
}
holder.tvcurrentDateTime.setText(data.get(position).getTime());
int i = holder.tvcurrentDateTime.getWidth() <------- Here it is return 0
holder.tvAction.setText(data.get(position).getAction());
holder.tvLatitude.setText(data.get(position).getLatitude());
holder.tvLongitude.setText(data.get(position).getLogitude());
return row;
}
私はそれを検索しましたが、そうする方法を見つけることができませんでした。
関連するコードは次のとおりです。
マイ リスト アクティビティ:
public class Activity_Log extends ListActivity {
PickupStatusDao puDao;
LogAdapter adapter;
List<LogModel> listOfDispatch;
private Object mItem;
private View childView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_log_xml);
puDao = new PickupStatusDao(this);
List<LogModel> lstResult = puDao.readAllLogData();
adapter = new LogAdapter(this, R.layout.log_item_row, lstResult);
setListAdapter(adapter);
}
}
私のlist_item(R.layout.log_item_row):
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
android:id="@+id/BodyTable"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="@+id/tableRow2"
style="@style/BodyRow"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tvCurrentDateTimeLog"
style="@style/BodyText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="this time"
android:textSize="20sp" />
<TextView
android:id="@+id/tvActionLog"
style="@style/BodyText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="this is action"
android:textSize="20sp" />
<TextView
android:id="@+id/tvlogitudeLog"
style="@style/BodyText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="logitude"
android:textSize="20sp" />
<TextView
android:id="@+id/tvlatitudeLog"
style="@style/BodyText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="latuide"
android:textSize="20sp" />
</TableRow>
</TableLayout>
リスト活動レイアウト (R.layout.activity_log_xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:id="@+id/HeaderTable"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow style="@style/HeaderRow" >
<TextView
style="@style/HeaderText"
android:layout_width="239dp"
android:text="Date" />
<TextView
style="@style/HeaderText"
android:layout_width="156dp"
android:text="Status" />
<TextView
style="@style/HeaderText"
android:layout_width="121dp"
android:text="Latitude" />
<TextView
style="@style/HeaderText"
android:layout_width="121dp"
android:text="Longitude" />
</TableRow>
</TableLayout>
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</ListView>
</LinearLayout>