我正在使用simplecursortreeadapter來填充可擴展列表視圖並希望在所有具有標題的子視圖的頂部有一行數據。如何將標題行添加到使用simplecursortreeadapter的可擴展列表視圖的子視圖列表
- 組1個名稱[EXPANDED]
- 報頭(日期,名稱,$)
- 兒童1(2017年7月12日,乍得,50.00)
- 兒童2 (08/11/2017,Mike,63.21)
- 組2名稱[擴大]
- 頭(日期,姓名,$)
- 兒童1(2017年3月25日,肯,23.97)
- 兒童2(2017年1月25日,威爾101.11)
- 組3 [摺疊]
是否有可能有包含3套頭文本(日期,姓名,$)與textviews只出現在該團體擴大了?由於SimpleCursorTreeAdapter處理將光標數據添加到視圖中,我不知道如何添加一行到該視圖或如何實現此目的。這可能嗎?
編輯:這是我的適配器類:
package com.example.myproject.michaelc.billme;
import android.content.Context;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.database.MergeCursor;
import android.support.v4.content.Loader;
import android.util.Log;
import android.widget.SimpleCursorTreeAdapter;
import com.example.myproject.michaelc.billme.data.BillMeContract;
import java.util.HashMap;
public class PayeeCursorAdapter extends SimpleCursorTreeAdapter {
private final String LOG_TAG = getClass().getSimpleName();
private PayeeActivity mActivity;
protected final HashMap<Integer, Integer> mGroupMap;
// No cursor is added to the adapter so that it only runs when the CursorLoader runs, instead of every time the activity does
public PayeeCursorAdapter(
Context context, // The activity where the adapter will be running
int groupLayout, // The .xml layout file for the group layout
int childLayout, // The .xml layout file for the child layout
String[] groupFrom, // String of column names in the cursor that is the data for each group item
int[] groupTo, // The ID of the views in the group layout that display the column from the groupFrom String[]
String[] childrenFrom, // String of column names in the cursor that is the data for each child item
int[] childrenTo) { // The ID of the views in the child layout that display the column from the childFrom String[]
super(context, null, groupLayout, groupFrom, groupTo, childLayout, childrenFrom, childrenTo);
mActivity = (PayeeActivity) context;
mGroupMap = new HashMap<Integer, Integer>();
}
@Override
protected Cursor getChildrenCursor(Cursor groupCursor) {
int groupPos = groupCursor.getPosition();
int groupId = groupCursor.getInt(groupCursor.getColumnIndex(BillMeContract.PayeeEntry._ID));
Log.d(LOG_TAG, "getChildrenCursor() for groupPos " + groupPos);
Log.d(LOG_TAG, "getChildrenCursor() for groupId " + groupId);
mGroupMap.put(groupId, groupPos);
Loader<Cursor> loader = mActivity.getSupportLoaderManager().getLoader(groupId);
if(loader != null && !loader.isReset()) {
mActivity.getSupportLoaderManager().restartLoader(groupId, null, mActivity);
} else {
mActivity.getSupportLoaderManager().initLoader(groupId, null, mActivity);
}
return null;
}
public HashMap<Integer, Integer> getGroupMap(){
return mGroupMap;
}
}
你可以發表你的適配器類? –
@KiranBennyJoseph在這裏,你去 –