Get all rows from SQLite

前端 未结 7 1828
执笔经年
执笔经年 2020-12-14 14:14

I have been trying to get all rows from the SQLite database. But I got only last row from the following codes.

FileChooser class:

p         


        
相关标签:
7条回答
  • 2020-12-14 15:05

    I have been looking into the same problem! I think your problem is related to where you identify the variable that you use to populate the ArrayList that you return. If you define it inside the loop, then it will always reference the last row in the table in the database. In order to avoid this, you have to identify it outside the loop:

    String name;
    if (cursor.moveToFirst()) {
    
            while (cursor.isAfterLast() == false) {
                name = cursor.getString(cursor
                        .getColumnIndex(countyname));
    
                list.add(name);
                cursor.moveToNext();
            }
    }
    
    0 讨论(0)
提交回复
热议问题