Putting cursor data into an array

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

    use this:

    if (cursor != null && cursor.getCount()>0){
      cursor.moveToFirst();
      do{
        for(int i = 0; i < cursor.getCount(); i ++){
          names.add(cursor.getString(i));
        }
      }while(cursor.moveToNext());
    }
    
    cursor.close();
    

提交回复
热议问题