2011-02-14 84 views
0

我想使用下面的代码将我的SQLite表的内容加载到ListView中。无法将我的SQLite数据加载到我的ListView中

myDbHelper = new DatabaseHelper(this); 
Cursor cursor = getData(); 
CursorAdapter dataSource = new SimpleCursorAdapter(this, R.layout.menu_item, cursor, fields, null); 
menuList.setAdapter(datasource); //My ListView 

private Cursor getData() { 
    SQLiteDatabase db = myDbHelper.getReadableDatabase(); 
    Cursor cursor = db.query(TABLE_NAME, FROM, null, null, null,null, ORDER_BY); 
    return cursor; 
} 

当我运行应用程序时,它通过此代码,然后引发错误。我是否使用正确的技术将数据添加到ListView?

+0

什么是错误/堆栈跟踪? – 2011-02-14 16:36:14

回答

0

您需要提供更多信息。

  • 它在哪里崩溃?
  • 它给出了什么错误?

您正在使用adapt但你不声明或将其设置为您的代码段什么 - 如果它是null,那么这将是一个问题。

menuList.setAdapter(adapt); //My ListView 

看看我的示例代码here对我如何使用ListView s的SQLite

+0

感谢您的回复。对于错字,我现在已经改变了,这是因为我用来分隔代码段。无论如何,感谢您的链接,它指出我在正确的方向,如果我使用你的技术,我认为这将解决我的问题 – user616076 2011-02-15 12:00:57

相关问题