java - 数据库添加项目到 ListView ?

标签 java android

我下载了这个数据库脚本,我想知道如何将其转换为将项目添加到 ListView 中..它是一个非常容易理解的数据库代码..

http://www.anotherandroidblog.com/wp-content/uploads/2010/08/AABDatabase.zip

这就是它的来源..

我猜它也可能在这里?

/**
 * retrieves a row from the database with the id number in the corresponding
 * user entry field
 */
private void retrieveRow()
{
    try
    {
        // The ArrayList that holds the row data
        ArrayList<Object> row;
        // ask the database manager to retrieve the row with the given rowID
        row = db.getRowAsArray(Long.parseLong(updateIDField.getText().toString()));

        // update the form fields to hold the retrieved data
        updateTextFieldOne.setText((String)row.get(1));
        updateTextFieldTwo.setText((String)row.get(2));
    }
    catch (Exception e)
    {
        Log.e("Retrieve Error", e.toString());
        e.printStackTrace();
    }
}

最佳答案

要将数据库中的项目添加到 ListView,您可以使用 ArrayList

1.) ArrayList<String> arrList = new ArrayList<String>();

2.) 从数据库中获取项目并将其添加到 ArrayList

        if(c.getCount() > 0){
            c.moveToFirst();
            for (int i = 0; i < c.getCount() - 1; i++) {
                arrList.add(c.getString(0));
                c.moveToNext();
            } 

3.) Then populate the Adapter with the ArrayList(arrList).

4.) And fill the ListView with the Adapter.

关于java - 数据库添加项目到 ListView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7550808/

相关文章:

java - 迁移到struts 2.3.24后,仍然不支持大于2GB的文件上传

android - fatal error : Box2D. h:没有那个文件或目录

android - 如何在 InfoWindow 中添加对象使其变大

android - 我可以让Firebase使用用户名登录过程吗?

java - 具有不同页码的 Viewpager

java - 用android的字符串计算

java - 如何使用实体关系不直接的 hibernate 条件连接多个表?

java - 为什么calculator.getValue()总是0?

java - 如何使用 Regex 和 DocumentFilter 限制点后超过两位数字?

java - 改变 HashMap 大小 (Java)