2016-04-15 46 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 –

相关问题