List of usage examples for android.database Cursor moveToNext
boolean moveToNext();
From source file:Main.java
public static ArrayList<ContentValues> getCity(SQLiteDatabase db, int dqx_dqxx01, boolean municipalities) { ArrayList<ContentValues> list = new ArrayList<ContentValues>(); ContentValues values = null;/*from w w w . j a v a 2s .com*/ Cursor cursor = db.query(TABLE_NAME, new String[] { "DQXX01", "DQXX02" }, "DQX_DQXX01=?", new String[] { "" + dqx_dqxx01 }, null, null, "DQXX01 ASC"); if (cursor != null) { if (municipalities) { cursor.moveToNext(); } while (cursor.moveToNext()) { values = new ContentValues(); values.put("city_id", cursor.getInt(0)); values.put("city", cursor.getString(1)); list.add(values); } } if (cursor != null && !cursor.isClosed()) { cursor.close(); } return list; }
From source file:Main.java
private static String[] convertCursorAsStringArrayWithCloseCursor(Cursor cursor, int colIdx) { String[] result = null;/*from w w w. j a v a 2 s . c o m*/ try { int resultCount = cursor.getCount(); if (resultCount > 0) { HashSet<String> phones = new HashSet<String>(resultCount); while (cursor.moveToNext()) { String phone = cursor.getString(0); phones.add(phone); } result = phones.toArray(new String[phones.size()]); } Log.d(TAG, "ConvertCursor As StringArray : found " + resultCount + " String converted from idx " + colIdx); } finally { cursor.close(); } return result; }
From source file:com.alchemiasoft.common.model.Book.java
public static List<Book> allFrom(@NonNull Cursor c) { final List<Book> books = new ArrayList<>(); while (c.moveToNext()) { final Book book = oneFrom(c); books.add(book);/*from w w w . ja va2s .com*/ } return books; }
From source file:Main.java
public static LinkedList<String> retrieveStringFromCursor(Cursor cursor, String columnName) { LinkedList<String> result = new LinkedList<String>(); if (null == cursor || 0 == cursor.getCount()) { return result; }//from www . ja va 2s . c om try { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { String str = cursor.getString(cursor.getColumnIndexOrThrow(columnName)); result.add(str); } } catch (Exception e) { //do nothing. } finally { cursor.close(); } return result; }
From source file:Main.java
public static LinkedList<Integer> retrieveIntegerFromCursor(Cursor cursor, String columnName) { if (null == cursor || 0 == cursor.getCount()) { return new LinkedList<Integer>(); }//from w ww . ja v a2 s . c o m LinkedList<Integer> ids = new LinkedList<Integer>(); try { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { int id = cursor.getInt(cursor.getColumnIndexOrThrow(columnName)); ids.add(new Integer(id)); } } catch (Exception e) { //do nothing. } finally { cursor.close(); } return ids; }
From source file:Main.java
public static int getOrientation(Context context, Uri uri) { Cursor cursor = null; try {/*from w w w .ja v a2 s.c om*/ cursor = context.getContentResolver().query(uri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); if (cursor == null) { return 0; } if (cursor.moveToNext()) { int ori = cursor.getInt(0); return ori; } else { return -1; } } catch (SQLiteException e) { return 0; } finally { if (cursor != null) { cursor.close(); } } }
From source file:Main.java
/** * get the sound list of the system/* ww w. j a v a 2 s . co m*/ */ public static ArrayList<String> getSystemRingList(Context con) { ArrayList<String> getArray = new ArrayList<String>(); ContentResolver cr = con.getContentResolver(); String[] cols = new String[] { MediaStore.Audio.Media.IS_RINGTONE, MediaStore.Audio.Media._ID, MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.DISPLAY_NAME }; Cursor cursor = cr.query(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, cols, null, null, null); if (cursor.moveToFirst()) { do { if (cursor.getString(0).equals("1")) { getArray.add(cursor.getString(2)); } } while (cursor.moveToNext()); } return getArray; }
From source file:de.escoand.readdaily.DownloadHandler.java
public static void stopDownload(final Context context, final String name) { Database db = Database.getInstance(context); Cursor c = db.getDownloads(); long id = 0;/*from ww w . ja v a 2 s.co m*/ // get download id while (c.moveToNext()) if (c.getString(c.getColumnIndex(Database.COLUMN_SUBSCRIPTION)).equals(name)) { id = c.getLong(c.getColumnIndex(Database.COLUMN_ID)); break; } c.close(); if (id <= 0) return; // stop download ((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).remove(id); db.removeDownload(id); }
From source file:Main.java
public static String getFirstCNLetterByContactId8(Context context, long contactId) { String result = ""; String[] projection = { "_id", "display_name", "data1", "sort_key" }; String where = Data.CONTACT_ID + "=?"; final String sortOrder = null; Cursor cursor = context.getContentResolver().query(PHONE_CONTACTS_URI, projection, where, new String[] { String.valueOf(contactId) }, sortOrder); if (cursor != null) { try {//from www . j a va 2 s . c o m if (cursor.getCount() > 0) { while (cursor.moveToNext()) { String nameLetters = cursor.getString(cursor.getColumnIndexOrThrow("sort_key")); if (null != nameLetters && !"".equals(nameLetters)) { result = nameLetters.substring(0, 1).toUpperCase(); break; } } } } finally { cursor.close(); } } return result; }
From source file:Main.java
public static String getLatestImage(Activity context) { String latestImage = null;// w w w . j a va 2 s .c om String[] items = { MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA }; Cursor cursor = context.managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, items, null, null, MediaStore.Images.Media._ID + " desc"); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { latestImage = cursor.getString(1); break; } } return latestImage; }