【发布时间】:2011-09-06 06:06:06
【问题描述】:
在我的应用程序中,我使用列表视图来显示带有菜肴名称的菜肴菜单
这是我使用适配器将查询中的数据绑定到列表视图的代码:
private void getDishes() {
DBAdapter db = new DBAdapter(this);
db.open();
Cursor cursor = db.getAllDishes();
cursor.moveToFirst();
Log.w("ppp","kk - " + cursor.moveToFirst());
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.list_item, cursor, new String[] { DBAdapter.DishName },
new int[] {R.id.dishName });
setListAdapter(adapter);
db.close();
}
我的查询代码如下所示:
public Cursor getAllDishes()
{
return db.query(DATABASE_TABLE, new String[] {DishName},null,null,null,null,null);
}
非常感谢任何帮助/cmets,因为我已经坚持了将近一周。
【问题讨论】:
-
我没有阅读代码,因为您可能需要改进您的问题。有什么问题,是什么导致你卡住了?
-
通过 Listview 查看本教程:vogella.de/articles/AndroidListView/article.html
-
对不起,我忘了添加,应用程序似乎无法使用第 1 篇文章中的代码运行,我做了一个 logcat 来检查查询是否有效并且它返回 true,这意味着值是空的吧?
标签: android listview simplecursoradapter