2

Quick question, I have a listview that's populated from a database through an AsyncTask. I use an if statement to decide which db method to get a cursor from. The db methods work great outside an asynctask, but only works inside the asynctask when the Log code is there.

if (i == 1) {
    c = cdb.getFive();
    Log.d("TAG5", DatabaseUtils.dumpCursorToString(c));
}

works, but

if (i == 1) {
    c = cdb.getFive();
    //Log.d("TAG5", DatabaseUtils.dumpCursorToString(c));
}

doesn't work. Any ideas why?

EDIT - That code is in doInBackground()

HitOdessit
  • 7,198
  • 4
  • 36
  • 59
Bill Gary
  • 2,987
  • 2
  • 15
  • 19
  • You should post some more code. Otherwise magic indeed. :P – rui.araujo Feb 16 '12 at 20:11
  • what code do you want, the full activity and db methods? – Bill Gary Feb 16 '12 at 20:16
  • @BillGary Maybe you should post the code for the method `dumpCursorToString`. And what exactly means works/doesn't work? Exceptions? – user Feb 16 '12 at 20:20
  • `dumpCursorToString` is from http://developer.android.com/reference/android/database/DatabaseUtils.html#dumpCursorToString%28android.database.Cursor%29 and it throws no errors, it just doesn't populate the listview. The listview is in a tabhost if that matters. – Bill Gary Feb 16 '12 at 20:21

1 Answers1

1

You should call c.moveToFirst() method before reading any data from Cursor.

Actually, method DatabaseUtils.dumpCursorToString() calls method moveToPosition(). What's why your code is working with logging and doesn't working without it.

HitOdessit
  • 7,198
  • 4
  • 36
  • 59