tags:

views:

491

answers:

1

Hi, I want to put a "All String" data (get from "Cursor") into an "Array". But I don't know why the "Array" just return one value? I'm get lost here. Can someone help me? This is my code snippet

private String[] getOneColumn(){        
    String[] myArray = null;     
    Cursor cursor = mDbHelper.fetchAllNotes();
    startManagingCursor(cursor);

    if(cursor.moveToFirst()){
     String myTitle = cursor.getString(cursor.getColumnIndex(SBooksDbAdapter.KEY_TITLE_RAW));
     myArray = myTitle.split(";");      
    }  

    return myArray;
}
+2  A: 

I'll suggest you to take a look here or here for some good examples of using cursors and databases (cursors were and still are a little troubling for me too).

As about the problem at hand, I think you forget to iterate through your Cursor's data (cursor.moveToNext(), cursor.moveToPosition(int)).

Good luck.

Dimitar Dimitrov
I see your provided link (anddev.org), but I think it old version, 1.5 not support anymore. Once again, I think I lost.
Dennie
The difference is just in method naming, I think, instead of cursor.first(), you call cursor.moveToFirst(), and instead of cursor.next() - cursor.moveToNext(), and you should be able to do the same. Also the notepad tutorial from the Android Project home site is compliant with SDK 1.5, so check it out too. What exactly do you want to do? You don't seem to iterate through the cursor's data, I think that's the problem with the single result. Getting all results is shown, or at least sketched in that first tutorial:if (cursor.moveToFirst()) { do {...} while (cursor.moveToNext()) }
Dimitar Dimitrov
Ok, I have tried that new code, But the return value (Array) something wrong? This code myArray = myTitle.split(";") . Is it true?
Dennie
I have edited my question, sorry for the inconvenient
Dennie