如何使用simpleCursorAdapter填充列表视图 [英] How to populate a listview using simpleCursorAdapter

查看:76
本文介绍了如何使用simpleCursorAdapter填充列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库适配器,用于从数据库表填充列表视图的布局文件。

我没有在代码中看到任何错误,但收到'应用程序已停止工作'的消息。 />
但是我觉得问题在于引发'simpleCursorAdapter ...'的行。

如果我评论该行并运行代码,则没有错误,例如'apps停止工作'。

任何人都可以帮助我,这样我就可以从Sqlite数据库中提取listview。

I have a database adapter,layout files for populating a listview from a database table.
I dont see any error in the code but get a message that 'apps has stopped working'.
However I feel that the problem lies at the line that raises the 'simpleCursorAdapter..'
If I comment that line and run the code there is NO error like 'apps stopped working'.
Can anyone help me out so that I can raise the listview from Sqlite database.

Cursor cursor= vivzHelper.getAllRows();
String [] from=new String[]{vivzHelper.NAME};
int[] to=new int[]{ R.id.item_name};
SimpleCursorAdapter dataAdapter;
dataAdapter=new SimpleCursorAdapter(this,R.layout.item_layout, cursor, from, to,0);
ListView listView = (ListView) findViewById(R.id.listView1);
listView.setAdapter(dataAdapter);



DBhelper的代码:


Code at DBhelper:

Cursor getAllRows( ){
    db = helper.getWritableDatabase();
    Cursor mCursor=null;
    String [] columns={VivzHelper.NAME};
    mCursor= db.query(VivzHelper.TABLE_NAME,columns,null,null,null,null,null);
    if (mCursor!=null) {
        mCursor.moveToFirst();
    }
    return mCursor;
}

推荐答案

你可以在这里找到解决方案



http://stackoverflow.com/questions / 6348672 / android-populate-listview-using-simplecursoradapter-about-to-loose-the-will-t [ ^ ]
you can find the solution here

http://stackoverflow.com/questions/6348672/android-populate-listview-using-simplecursoradapter-about-to-loose-the-will-t[^]


这篇关于如何使用simpleCursorAdapter填充列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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