2016-04-15 106 views
9

設置:我有一個本地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 
} 
+0

轉儲'movieCursor'(DatabaseUtils#dumpCursor) – pskink

+0

打印一切就好了... – Maverick283

+0

覆蓋測試'bindGroupView' /'bindChildView',看看他們是所謂的,你可以叫'DatabaseUtils在他們裏面#dumpCurrentRow' – pskink

回答

-1

我與我們的愛好/作業又愛又恨:你有什麼工作,在某些時候,這東西似乎完全獨立的變化,再後來你的事情不再工作。這是發生在這裏,並沒有辦法你可以猜到它:

隨着我的設備更新到棉花糖它仍然可以讀取我以前使用的ArrayList,但無法讀取數據庫了...爲什麼它可以仍然轉儲光標...?我不知道。但只要我發現你必須請求移動中的權限,並且實現它,它的工作原理......或多或少。

+0

我喜歡我們的工作:D –