我有一個ExpandableListView小部件,它使用基於SimpleCursorTreeAdapter的適配器進行填充,如下所示。我查詢我的SQL數據庫的ListView的組標題以及一個布爾值,以確定該組是否應該展開或摺疊(這是在光標中返回)。然後我將這個光標提供給我的適配器,並且列表被填充和顯示。根據傳遞的Cursor值在ExpandableListView中展開/摺疊組節點?
我唯一不能做的事情是讓ListView中的組節點根據提供的Cursor中的布爾值展開或摺疊。我想在包含此ExpandableListView小部件的活動初始創建,加載和顯示時發生這種情況。
有沒有辦法讓我的適配器採用Cursor對象中提供的布爾值並使用它們展開或摺疊這些組節點?
public class MyExpandableListAdapter extends SimpleCursorTreeAdapter
{
public MyExpandableListAdapter (Cursor cursor, Context context, int groupLayout,
int childLayout,
String[] groupFrom, int[] groupTo,
String[]childrenFrom,int[]childrenTo)
{
super(context,cursor,groupLayout,groupFrom,groupTo,childLayout,childrenFrom,childrenTo);
}
@Override
protected Cursor getChildrenCursor(Cursor groupCursor)
{
String strCategory =
groupCursor.getString(groupCursor.getColumnIndex("strCategory"));
Cursor cur = mainActivity.mDbHelper.getCardTitlesForCategory(strCategory);
return cur;
}
}
感謝您的建議和意見。
我在做類似的東西這裏http://stackoverflow.com/questions/10611927/simplecursortreeadapter-and-cursorloader – toobsco42 2012-05-16 07:19:05