不能我的SQLite的数据加载到我的ListView [英] Can't load my SQLite data into my ListView

查看:121
本文介绍了不能我的SQLite的数据加载到我的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用下面的code加载我的SQLite表的内容变成一个ListView。

I'm trying to load the contents of my SQLite table into a ListView using the following code.

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;  
}  

当我运行它通过这个code,然后抛出一个错误的应用程序。我使用正确的技术来将数据添加到ListView?

When I run the app it passes through this code and then throws an error. Am I using the correct technique for adding data to a ListView?

推荐答案

您需要给多一点信息。

You need to give a little more information.


  • 哪里不崩溃?

  • 什么是错误,它给?

您正在使用调整,但你不申报,或将其设置为任何东西在你的code片段 - 如果它是,那么这将是一个问题。

You are using adapt but you do not declare it or set it to anything in your code snippet - if it's null, then that will be a problem.

menuList.setAdapter(adapt);  //My ListView  

看看我的例子code <一个href=\"http://stackoverflow.com/questions/4897800/show-data-in-my-android-appsaving-works-just-fine-now/4963989#4963989\">here对于如何使用的ListView s的的SQLite

Take a look at my example code here for how I use ListViews with SQLite.

这篇关于不能我的SQLite的数据加载到我的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆