設置:我有一個本地SQLite數據庫,用於存放電影的放映時間。一些列的是「日期」,「ID」,「時代」 ......使用SQLite中的數據填充ExpandableListView
意圖: 我希望把所有這些場次的入ExpandableListView而日期將是父項目。
問題:什麼都不顯示。一點都沒有。我很難理解爲什麼。有人有想法嗎?
一些代碼:最重要的東西是在最頂端,得到的少,當你向下滾動不那麼重要了......
這是我想要實現這個與被調用的代碼在活動的onCreate()
:
String sql = "SELECT rowid _id,* FROM " + Statics.DBSHOWS + ";";
Cursor movieCursor = database.rawQuery(sql,null);
movieCursor.moveToFirst();
adapter = new ExpandableListAdapter(movieCursor, this,
android.R.layout.simple_list_item_1,
android.R.layout.simple_list_item_2,
new String[]{Statics.DBSHOWS_DATE},
new int[]{android.R.id.text1},
new String[]{Statics.DBSHOWS_TIME, Statics.DBSHOWS_ID},
new int[]{android.R.id.text1, android.R.id.text2});
movieListView.setAdapter(adapter);
這是我ExpandableListAdapter:
public class ExpandableListAdapter extends SimpleCursorTreeAdapter {
Context context;
public ExpandableListAdapter(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);
this.context = context;
}
@Override
protected void bindChildView(View view, Context context, Cursor cursor, boolean isLastChild) {
super.bindChildView(view, context, cursor, isLastChild);
System.out.println("Dumping form Childview");
DatabaseUtils.dumpCurrentRow(cursor);
}
@Override
protected void bindGroupView(View view, Context context, Cursor cursor, boolean isExpanded) {
super.bindGroupView(view, context, cursor, isExpanded);
if(view==null){
System.out.println("View is null!!");
}
System.out.println("Dumping form Groupview");
DatabaseUtils.dumpCurrentRow(cursor);
}
@Override
protected Cursor getChildrenCursor(Cursor groupCursor) {
int dateInMillis = groupCursor.getInt(groupCursor.getColumnIndex(Statics.DBSHOWS_DATE));
Cursor childCursor = DataHandler.getShowsForDate(dateInMillis);
childCursor.moveToFirst();
return childCursor;
}
}
兩個Override
方法bindChildView(...)
和bindGroupView(...)
進行測試。正如預期的那樣,下面的輸出印:
Dumping form Groupview
0 {
_id=1
Id=117451
Date=15.04.2016
Time=20:15
Movie_Id=2181
Hall=0
Cards_Sold=0
}
轉儲'movieCursor'(DatabaseUtils#dumpCursor) – pskink
打印一切就好了... – Maverick283
覆蓋測試'bindGroupView' /'bindChildView',看看他們是所謂的,你可以叫'DatabaseUtils在他們裏面#dumpCurrentRow' – pskink