Output values found in cursor to logcat? - Android Output values found in cursor to logcat? - Android database database

Output values found in cursor to logcat? - Android


Android has provided a specific class just for debugging Cursors. It is called DatabaseUtils.

Call the method dumpCursorToString() to view the contents of your cursor.

This helper loops through and prints out the content of the Cursor for you, and returns the cursor to its original position so that it doesn't mess up your iterating logic.


use this before cursor.moveToFirst()

Log.v("Cursor Object", DatabaseUtils.dumpCursorToString(cursor))


If you intend to write contents of the cursor to the logcat row by row you can use code as below:

if (cursor.moveToFirst()) {    do {        StringBuilder sb = new StringBuilder();        int columnsQty = cursor.getColumnCount();        for (int idx=0; idx<columnsQty; ++idx) {            sb.append(cursor.getString(idx));            if (idx < columnsQty - 1)                sb.append("; ");        }        Log.v(TAG, String.format("Row: %d, Values: %s", cursor.getPosition(),             sb.toString()));    } while (cursor.moveToNext());}