List of usage examples for android.database Cursor moveToNext
boolean moveToNext();
From source file:Main.java
public static ArrayList<String> cursorToArrayList(Cursor cursor) { ArrayList<String> list = new ArrayList<String>(); cursor.moveToFirst();/*from w ww .j ava2s . c om*/ while (cursor.isAfterLast() == false) { list.add(cursor.getString(cursor.getColumnIndex("name"))); cursor.moveToNext(); } return list; }
From source file:fr.mixit.android.io.JSONHandler.java
/** * Returns those id's from a {@link android.net.Uri} that were not found in a given set. *//*from w w w . java2 s .c o m*/ protected static HashSet<String> getLostIds(Set<String> ids, Uri uri, String[] projection, int idColumnIndex, ContentResolver resolver) { final HashSet<String> lostIds = Sets.newHashSet(); final Cursor cursor = resolver.query(uri, projection, null, null, null); try { while (cursor.moveToNext()) { final String id = cursor.getString(idColumnIndex); if (!ids.contains(id)) { lostIds.add(id); } } } finally { cursor.close(); } if (!lostIds.isEmpty()) { Log.d(TAG, "Found " + lostIds.size() + " for " + uri.toString() + " that need to be removed."); } return lostIds; }
From source file:Main.java
private static String getCoverPath(Context context, long albumId) { String path = null;/*from w ww . j a v a 2 s . co m*/ Cursor cursor = context.getContentResolver().query( Uri.parse("content://media/external/audio/albums/" + albumId), new String[] { "album_art" }, null, null, null); if (cursor != null) { cursor.moveToNext(); path = cursor.getString(0); cursor.close(); } return path; }
From source file:Main.java
private static Set<Integer> getAllAvailableProtocolVersions(Context context) { ContentResolver contentResolver = context.getContentResolver(); Set<Integer> allAvailableVersions = new HashSet<Integer>(); Uri uri = Uri.parse("content://appsneva.facebook.orca.provider.MessengerPlatformProvider/versions"); String[] projection = new String[] { "version" }; Cursor c = contentResolver.query(uri, projection, null, null, null); if (c != null) { try {/*from w ww . ja va 2 s . com*/ int versionColumnIndex = c.getColumnIndex("version"); while (c.moveToNext()) { int version = c.getInt(versionColumnIndex); allAvailableVersions.add(version); } } finally { c.close(); } } return allAvailableVersions; }
From source file:Main.java
private static Set<Integer> getAllAvailableProtocolVersions(Context context) { ContentResolver contentResolver = context.getContentResolver(); Set<Integer> allAvailableVersions = new HashSet<Integer>(); Uri uri = Uri.parse("content://com.facebook.orca.provider.MessengerPlatformProvider/versions"); String[] projection = new String[] { "version" }; Cursor c = contentResolver.query(uri, projection, null, null, null); if (c != null) { try {//from w w w . j av a2 s.c o m int versionColumnIndex = c.getColumnIndex("version"); while (c.moveToNext()) { int version = c.getInt(versionColumnIndex); allAvailableVersions.add(version); } } finally { c.close(); } } return allAvailableVersions; }
From source file:Main.java
public static ArrayList<ContentValues> getArea(SQLiteDatabase db, int dqx_dqxx01) { ArrayList<ContentValues> list = new ArrayList<ContentValues>(); ContentValues values = null;//from w w w . jav a 2 s . c om Cursor cursor = db.query(TABLE_NAME, new String[] { "DQXX01", "DQXX02", "DQXX05" }, "DQX_DQXX01=?", new String[] { "" + dqx_dqxx01 }, null, null, "DQXX01 ASC"); if (cursor != null) { while (cursor.moveToNext()) { values = new ContentValues(); values.put("area_id", cursor.getInt(0)); values.put("area", cursor.getString(1)); values.put("full_area", cursor.getString(2)); list.add(values); } } if (cursor != null && !cursor.isClosed()) { cursor.close(); } return list; }
From source file:Main.java
public static ArrayList<String> cursorToArrayList(Cursor cursor) { ArrayList<String> list = new ArrayList<>(); if (cursor == null) return list; cursor.moveToFirst();/*from ww w .j a v a 2s. c om*/ while (!cursor.isAfterLast()) { list.add(cursor.getString(0)); cursor.moveToNext(); } return list; }
From source file:edu.mit.mobile.android.locast.data.tags.TaggableUtils.java
public static Set<String> getTags(ContentProviderClient cpc, Uri tagDir) throws RemoteException { final Set<String> tags = new HashSet<String>(); final Cursor c = cpc.query(tagDir, TAG_PROJECTION, null, null, null); try {/*from ww w . j av a2 s .com*/ final int tagNameCol = c.getColumnIndexOrThrow(Tag.COL_NAME); while (c.moveToNext()) { tags.add(c.getString(tagNameCol)); } } finally { c.close(); } return tags; }
From source file:Main.java
/** * Get specific row values from the database, * e.g. all years stored in the database or * all months of a year stored in the database or * all days in a month of a year stored in the database * * @param db//from www .j av a 2 s. c o m * pointer to database * @param requestField * requested row from db * "year" returns all year values found * "month" returns all month values found in year <code>requestLimiterYear</code> * "day" returns all day values found in month <code>requestLimiterMonth</code> * and year <code>requestLimiterYear</code> * @param requestLimiterMonth * limiter for request * unused if requestField is "year" * unused if requestField is "month" * month if requestField is "day" * @param requestLimiterYear * limiter for request * unused if requestField is "year" * year if requestField is "month" * year if requestField is "day" * * @return <code>ArrayList<Integer></code> * array list with all entries found */ public static ArrayList<Integer> getEntries(SQLiteDatabase db, String requestField, int requestLimiterMonth, int requestLimiterYear) { /** Array list holding the found values */ ArrayList<Integer> returnArray = new ArrayList<>(); /** Limiter for row search */ String queryRequest = "select distinct " + requestField + " from " + TABLE_NAME; if (requestField.equalsIgnoreCase("day")) { queryRequest += " where month = " + String.valueOf(requestLimiterMonth) + " and year = " + String.valueOf(requestLimiterYear); } else if (requestField.equalsIgnoreCase("month")) { queryRequest += " where year = " + String.valueOf(requestLimiterYear); } /** Cursor holding the records of a day */ Cursor allRows = db.rawQuery(queryRequest, null); allRows.moveToFirst(); for (int i = 0; i < allRows.getCount(); i++) { returnArray.add(allRows.getInt(0)); allRows.moveToNext(); } allRows.close(); return returnArray; }
From source file:Main.java
public static Map<String, Integer> getCity(SQLiteDatabase db, String tableName, int dqx_dqxx01, boolean municipalities) { Map<String, Integer> cityMap = new LinkedHashMap<String, Integer>(); Cursor cursor = db.query(tableName, new String[] { "DQXX02", "DQXX01" }, "DQX_DQXX01=?", new String[] { "" + dqx_dqxx01 }, null, null, "DQXX01 ASC"); if (cursor != null) { if (municipalities) { cursor.moveToNext(); }//from w w w . j a v a 2 s . c om while (cursor.moveToNext()) { cityMap.put(cursor.getString(0), cursor.getInt(1)); } } if (cursor != null && !cursor.isClosed()) { cursor.close(); } return cityMap; }