Example usage for android.database Cursor moveToNext

List of usage examples for android.database Cursor moveToNext

Introduction

In this page you can find the example usage for android.database Cursor moveToNext.

Prototype

boolean moveToNext();

Source Link

Document

Move the cursor to the next row.

Usage

From source file:Main.java

public static String CursorToJson(Cursor cursor) {
    do {/*ww  w  .ja  v a 2s  .  c om*/
        if (!cursor.moveToNext()) {
            return "";
        }
        int i = 0;
        while (i < cursor.getCount()) {
            cursor.getString(0);
            i++;
        }
    } while (true);
}

From source file:Main.java

public static boolean isTableExists(SQLiteDatabase db, String tableName) {
    String sql = "SELECT name FROM sqlite_master WHERE type = 'table' AND name = ? ";
    String paras[] = { tableName };
    try {/*w ww.j a  v  a  2 s .  co  m*/
        Cursor cursor = db.rawQuery(sql, paras);
        cursor.moveToNext();
        String name = cursor.getString(cursor.getColumnIndex("name"));
        if (name.equals(tableName)) {
            return true;
        } else {
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:Main.java

public static ArrayList<String> queryDay(SQLiteDatabase db) {
    ArrayList<String> dayList = new ArrayList<String>();

    String sqlStr = "select distinct date from " + TABLE_NAME + " order by _id desc";

    Cursor cursor = db.rawQuery(sqlStr, null);

    while (cursor.moveToNext()) {
        dayList.add(cursor.getString(0));
    }//from  w  w  w. j a va 2 s. com

    return dayList;
}

From source file:Main.java

private static ArrayList<String> readStrings(SQLiteDatabase db, String query, int colIdx) {
    ArrayList<String> rows = new ArrayList<String>();
    Cursor c = db.rawQuery(query, null);
    while (c.moveToNext()) {
        rows.add(c.getString(colIdx));//www  . j a v a  2 s  .  c  o m
    }
    c.close();
    return rows;
}

From source file:Main.java

public static int getGroupCount(SQLiteDatabase db) {
    int count = 0;
    Cursor cursor = db.rawQuery("select count(*) from classlist", null);
    cursor.moveToNext();
    count = cursor.getInt(0);//from   w  w  w .  java  2 s .  c o m
    cursor.close();
    return count;
}

From source file:Main.java

public static SparseIntArray readCountArray(Cursor cursor) {

    SparseIntArray countMap = new SparseIntArray();
    while (cursor.moveToNext()) {
        countMap.put(cursor.getInt(ID_INDEX), cursor.getInt(TASK_COUNT_INDEX));
    }//w  w w.jav  a  2  s . c  o  m
    return countMap;
}

From source file:Main.java

public static String[] singleRecordToArray(Cursor cursor) {
    String[] result = null;//w w  w  . j ava2s  .  com
    try {
        if (cursor.moveToNext()) {
            result = new String[cursor.getColumnCount()];
            fillArray(cursor, result);
        }
    } finally {
        closeQuietly(cursor);
    }
    return result;
}

From source file:Main.java

/**
 * to query columns names of a Table from database
 * @author wajdihh//ww w . j  a  va  2s  .  co m
 * @param pDatabase
 * @param pTableName
 * @return list of columns
 */
public static ArrayList<String> getTableColumnsNames(SQLiteDatabase pDatabase, String pTableName) {
    ArrayList<String> lListOfColumns = new ArrayList<String>();
    Cursor lCursor = pDatabase.rawQuery("PRAGMA table_info(" + pTableName + ")", null);
    while (lCursor.moveToNext())
        lListOfColumns.add(lCursor.getString(1));
    return lListOfColumns;
}

From source file:Main.java

public static List<String> listAlldir(Context cxt) {
    Intent intent = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    Uri uri = intent.getData();//from ww w. j  a  va2  s . co  m
    List<String> list = new ArrayList<String>();
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = cxt.getContentResolver().query(uri, proj, null, null, null);
    while (cursor.moveToNext()) {
        String path = cursor.getString(0);
        list.add(new File(path).getAbsolutePath());
    }
    return list;
}

From source file:Main.java

public static String getVideoPath(Context context, Intent data) {
    Cursor cursor = context.getContentResolver().query(data.getData(), null, null, null, null);
    if (cursor != null && cursor.moveToNext()) {
        String filePath = cursor.getString(cursor.getColumnIndex(VideoColumns.DATA));
        return filePath;
    } else if (data != null && data.getData() != null) {
        return data.getData().getEncodedPath();
    }//w w  w  .  j  a v  a 2  s .  c  o m
    return null;
}