Putting cursor data into an array

后端 未结 5 425
南方客
南方客 2021-02-04 20:57

Being new in Android, I am having trouble dealing with the following:

public String[] getContacts(){
    Cursor cursor = getReadableDatabase().rawQuery(\"SELECT          


        
5条回答
  •  无人及你
    2021-02-04 21:16

    I hope its useful to you.

     public static ArrayList SelectAll(DbHelper dbaConnection) {
                ArrayList Agents_aList = new ArrayList();
    
                SQLiteDatabase sqldb = dbaConnection.openDataBase();
                Cursor cursor = sqldb.rawQuery("SELECT * FROM Agents", null);
                if (cursor != null)// If Cursordepot is null then do
                                    // nothing
                {
                    if (cursor.moveToFirst()) {
    
    
                        do {
                            // Set agents information in model.
                            ModelAgents Agents = new ModelAgents();
                            Agents.setID(cursor.getInt(cursor
                                    .getColumnIndex(TblAgents.ID)));
                            Agents.setCode(cursor.getString(cursor
                                    .getColumnIndex(TblAgents.CODE)));
                            Agents.setName(cursor.getString(cursor
                                    .getColumnIndex(TblAgents.NAME)));
    
                            Agents_aList.add(Agents);
                        } while (cursor.moveToNext());
                    }
                    cursor.close();
                }
    
                sqldb.close();
    
                return Agents_aList;
    
            }
    

提交回复
热议问题