如何將ResourceCursorTreeAdapter與以下構造函數一起使用?如何在Android中使用ResourceCursorTreeAdapter和展開和摺疊的組視圖?
ResourceCursorTreeAdapter(Context context, Cursor cursor, int collapsedGroupLayout, int expandedGroupLayout, int childLayout)
我想如下使用它:
_resultsCursorTreeAdapter = new ResourceCursorTreeAdapter(_resultsList.getContext(), _dbAdapter.getAllGroups(),
R.layout.timing_group_view_collapsed, R.layout.timing_group_view_expanded, R.layout.timing_result_view) {
@Override
protected Cursor getChildrenCursor(Cursor groupCursor) {
// Given the group, we return a cursor for all the children within that group
int groupId = groupCursor.getInt(0);
Cursor childCursor = _dbAdapter.getContractionsForGroup(groupId);
return childCursor;
}
@Override
protected void bindGroupView(View groupView, Context context, Cursor cursor,
boolean isExpanded) {
TimingGroupView timingGroupItem = null;
if(groupView instanceof LinearLayout){
Log.i("TimingGroupView", "Has Header");
LinearLayout layout = (LinearLayout)groupView;
timingGroupItem = (TimingGroupView) layout.getChildAt(0);
} else{
Log.i("TimingGroupView", "No Header");
timingGroupItem = (TimingGroupView) groupView;
}
...
如果組節點展開,我希望組節點包括每一行被保持在一個表中的標題一個孩子節點。 timing_group_view_expanded.xml和timing_group_view_collapsed.xml顯示在這個問題的底部。出於某種原因,無論組節點是展開還是摺疊,都不會使用group_view_expanded。我使用這個錯誤嗎?是否有其他人能夠使用此構造函數獲取ResourceCursorTreeAdapter?
timing_group_view_expanded.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/timing_group_view"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/header_timing_color">
<com.contractiontracker.TimingGroupView
android:id="@+id/timing_group_item" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginLeft="30px" android:padding="10dp"
android:scrollbars="vertical"
android:fadingEdge="vertical"
android:background="@color/header_timing_color"
android:textColor="@color/text_color"/>
<com.contractiontracker.RowLayout android:id="@+id/timing_group_view"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/header_color" android:textColor="@color/text_color">
<TextView android:id="@+id/interval_header"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Interval" android:layout_weight="1"
android:layout_gravity="left|bottom" android:gravity="center"
android:textColor="@color/text_color">
</TextView>
<TextView android:id="@+id/duration_header"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Duration" android:layout_weight="1"
android:layout_gravity="center_horizontal|bottom" android:gravity="center"
android:textColor="@color/text_color"
>
</TextView>
<TextView android:id="@+id/intensity_header"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Intensity" android:layout_weight="1"
android:layout_gravity="right|bottom" android:gravity="center"
android:textColor="@color/text_color"
>
</TextView>
</com.contractiontracker.RowLayout>
</LinearLayout>
timing_group_view_collapsed.xml如下所示:
<?xml version="1.0" encoding="utf-8"?>
<com.contractiontracker.TimingGroupView
android:id="@+id/timing_group_item"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="50px"
android:padding="10dp"
android:scrollbars="vertical"
android:textColor="@color/text_color"
android:fadingEdge="vertical"/>
我認爲你需要檢查'convertview == null'否則每一次新groupview將被創建並列表項的概念不會在這裏工作,導致缺乏業績在滾動等 – kAmol 2017-04-26 10:26:07