Putting cursor data into an array

后端 未结 5 489
南方客
南方客 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:26

    Try to put the data into the ArrayList as below:

       public ArrayList getContacts(){
            Cursor cursor = getReadableDatabase().rawQuery("SELECT name FROM contacts", null);
            ArrayList names=new ArrayList();
            if (cursor != null)
            {
                if (cursor.moveToFirst()) {
                    for(int i = 0; i < cursor.getCount(); i ++){
                          names.add(cursor.getString(i));
                       }
                   }
           cursor.close();
         }
         return names;
      }
    

提交回复
热议问题