【发布时间】:2011-05-05 20:05:07
【问题描述】:
我正在尝试使用数据库中的列填充 ListView。我可以成功实现这一点,但问题是我想根据 id 是否与 PendingIntent 匹配来使用不同的布局资源。
这是为了检查是否存在带有 rowid 的警报,并且我计划在列表视图中提供视觉反馈,以向用户显示存在哪些警报。我可以根据 PendingIntents 成功检查 rowid 并获得返回布尔值。
我遇到的问题是使用不同行的不同布局资源填充 ListView(这甚至可能吗?),我不知道从哪里开始。
我目前有以下代码:
for(int x = 0; x < numNotes; x++) {
if(existAlarm(intarray[x])){
String[] from = new String[] { TodoDbAdapter.KEY_SUMMARY };
int[] to = new int[] { R.id.label1};
cursor = dbHelper.fetchTodo(intarray[x]);
SimpleCursorAdapter notes = new SimpleCursorAdapter(this,
R.layout.todo_row_green, cursor, from, to);
setListAdapter(notes);
} else if (!existAlarm(intarray[x])){
String[] from = new String[] { TodoDbAdapter.KEY_SUMMARY };
int[] to = new int[] { R.id.label};
cursor = dbHelper.fetchTodo(intarray[x]);
SimpleCursorAdapter notes = new SimpleCursorAdapter(this,
R.layout.todo_row, cursor, from, to);
setListAdapter(notes);
}
}
但 ListView 只显示循环中的最终数据库条目。
我将非常感谢任何指导,谢谢。
【问题讨论】:
标签: java android sqlite android-listview