get Cursor Contents - Android Database

Android examples for Database:Cursor Get

Description

get Cursor Contents

Demo Code


//package com.java2s;

import android.database.Cursor;

public class Main {

    public static String getCursorContents(Cursor cursor) {
        String[] columns = cursor.getColumnNames();
        StringBuilder builder = new StringBuilder(256);
        for (int row = 1; cursor.moveToNext(); row++) {
            builder.append("[rowno=" + row + ":");
            for (int i = 0; i < columns.length - 1; i++) {
                builder.append(columns[i])
                        .append("=")
                        .append(cursor.getString(cursor
                                .getColumnIndex(columns[i]))).append(",");
            }//from   w w  w  .  j a  v  a 2s  . c om
            builder.append(columns[columns.length - 1])
                    .append("=")
                    .append(cursor.getString(cursor
                            .getColumnIndex(columns[columns.length - 1])))
                    .append("]; ");
        }
        ;
        cursor.moveToFirst();
        cursor.moveToPrevious();
        return builder.toString();
    }
}

Related Tutorials