get Cursor Column - Android Database

Android examples for Database:Cursor Column

Description

get Cursor Column

Demo Code


//package com.java2s;

import android.database.Cursor;

public class Main {
    public static String getCursorColumn(Cursor cursor) {
        cursor.moveToFirst();//from www .  j av a2 s . c o  m
        StringBuilder sb = new StringBuilder();

        int columnsCount = cursor.getColumnCount();
        int count = cursor.getCount();
        sb.append("columnsCount = " + columnsCount + " count = " + count
                + "\n");

        for (int i = 0; i < columnsCount; i++) {
            sb.append(cursor.getColumnName(i) + " ("
                    + getType(cursor.getType(i)) + ")  ");
        }
        sb.append((char) 10);
        return sb.toString();
    }

    public static String getType(int type) {
        switch (type) {
        case Cursor.FIELD_TYPE_NULL:
            return "null";
        case Cursor.FIELD_TYPE_INTEGER:
            return "integer";
        case Cursor.FIELD_TYPE_FLOAT:
            return "float";
        case Cursor.FIELD_TYPE_STRING:
            return "string";
        case Cursor.FIELD_TYPE_BLOB:
            return "blob";
        }
        return "inv:" + type;
    }
}

Related Tutorials