create Cursor Copy - Android Database

Android examples for Database:Cursor

Description

create Cursor Copy

Demo Code


//package com.java2s;
import android.database.Cursor;
import android.database.MatrixCursor;

public class Main {
    public static Cursor createCopy(Cursor c) {
        MatrixCursor mc = new MatrixCursor(c.getColumnNames());
        int cols = c.getColumnCount();

        if (c.moveToFirst()) {
            do {// w  w  w.j a  va 2 s .c  o  m
                Object[] row = new Object[cols];
                for (int col = 0; col < cols; col++) {
                    row[col] = c.getString(col);
                }
                mc.addRow(row);
            } while (c.moveToNext());
        }
        return mc;
    }
}

Related Tutorials