带有ListView的Android TodoApp - 列表不会显示

时间:2014-12-06 10:48:23

标签: java android sqlite listview android-listview

我正在编写一个简单的todo-app并在listView上工作。按照教程http://www.vogella.com/tutorials/AndroidListView/article.html#tutorial_ownadapter

我的问题是todos列表没有显示在listView中。我没有得到任何异常或错误,表明它无法正常工作。

我正在使用android sqlite数据库。当我开始活动时,我将对象写入数据库并将其读出,并将其打印在日志中。所以这部分工作正常,你可以在日志中看到。

然后我将对象添加到我自己的适配器并将适配器设置为listView。

我不知道出了什么问题。这是我的项目:https://github.com/Visores/de.fhb.android.todoapp/tree/master/MyTodoApp

以下是app开始活动后的日志:

   12-06 06:02:46.977: I/ActivityManager(1261): Start proc de.fhb.maus.android.mytodoapp for activity de.fhb.maus.android.mytodoapp/.activities.LoginActivity: pid=2576 uid=10064 gids={50064}
12-06 06:02:47.117: D/dalvikvm(2576): GC_FOR_ALLOC freed 36K, 4% free 3552K/3680K, paused 31ms, total 34ms
12-06 06:02:47.227: D/(2576): HostConnection::get() New Host Connection established 0xb7dc0a70, tid 2576
12-06 06:02:47.247: W/EGL_emulation(2576): eglSurfaceAttrib not implemented
12-06 06:02:47.257: D/OpenGLRenderer(2576): Enabling debug mode 0
12-06 06:02:47.567: I/ActivityManager(1261): Displayed de.fhb.maus.android.mytodoapp/.activities.LoginActivity: +609ms (total +7s839ms)
12-06 06:02:49.237: I/ActivityManager(1261): START u0 {cmp=de.fhb.maus.android.mytodoapp/.activities.TodoOverviewActivity} from pid 2576
12-06 06:02:49.277: D/dalvikvm(2576): GC_FOR_ALLOC freed 105K, 5% free 3960K/4140K, paused 2ms, total 3ms
12-06 06:02:49.287: D/dalvikvm(2576): GC_FOR_ALLOC freed 7K, 3% free 4264K/4368K, paused 2ms, total 2ms
12-06 06:02:49.297: I/dalvikvm-heap(2576): Grow heap (frag case) to 6.654MB for 2536932-byte allocation
12-06 06:02:49.317: D/dalvikvm(2576): GC_FOR_ALLOC freed 1K, 2% free 6740K/6848K, paused 18ms, total 18ms
12-06 06:02:49.387: D/Todos(2576): [Todo [id=1, name=one, description=one, isDone=false, isImportant=true, maturityDate=1231232], Todo [id=2, name=two, description=two, isDone=true, isImportant=true, maturityDate=1231232], Todo [id=3, name=three, description=three, isDone=true, isImportant=false, maturityDate=1231232], Todo [id=4, name=four, description=four, isDone=true, isImportant=true, maturityDate=1231232]]
12-06 06:02:49.427: W/EGL_emulation(2576): eglSurfaceAttrib not implemented
12-06 06:02:49.457: I/ActivityManager(1261): Displayed de.fhb.maus.android.mytodoapp/.activities.TodoOverviewActivity: +220ms

问候Visores

活动:https://github.com/Visores/de.fhb.android.todoapp/blob/master/MyTodoApp/src/de/fhb/maus/android/mytodoapp/activities/TodoOverviewActivity.java

适配器: https://github.com/Visores/de.fhb.android.todoapp/blob/master/MyTodoApp/src/de/fhb/maus/android/mytodoapp/adapter/TodoArrayAdapter.java

列表行的

布局: https://github.com/Visores/de.fhb.android.todoapp/blob/master/MyTodoApp/res/layout/rowlayout.xml

活动布局: https://github.com/Visores/de.fhb.android.todoapp/blob/master/MyTodoApp/res/layout/todo_overview.xml

1 个答案:

答案 0 :(得分:2)

考虑改变

super(context, R.layout.rowlayout);

super(context, R.layout.rowlayout,todos);

或覆盖getCount方法

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return todos.size();
}