1

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;
}

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I see your provided link (anddev.org), but I think it old version, 1.5 not support anymore. Once again, I think I lost.
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()) }
Ok, I have tried that new code, But the return value (Array) something wrong? This code myArray = myTitle.split(";") . Is it true?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.