List of usage examples for android.database Cursor getColumnCount
int getColumnCount();
From source file:com.mfcoding.locationBP.UI.fragments.LocationListFragment.java
/** * {@inheritDoc}/*from w w w . j a v a 2 s. c o m*/ * When the loading has completed, assign the cursor to the adapter / list. */ public void onLoadFinished(Loader<Cursor> loader, Cursor data) { Log.d(TAG, "onLoadFinished # columns:" + data.getColumnCount()); for (int i = 0; i < data.getColumnCount(); i++) { Log.d(TAG, String.format("data.column[%d]=%s", i, data.getColumnName(i))); } adapter.swapCursor(data); }
From source file:eu.geopaparazzi.library.database.DbCursorAdapter.java
public void bindView(View view, Context context, Cursor cursor) { StringBuilder sb = new StringBuilder(); TextView textView = (TextView) view; for (int i = 0; i < cursor.getColumnCount(); i++) { String field = cursor.getColumnName(i); if (field.equals("_id")) { continue; }/* w w w .java 2s . c om*/ String value = cursor.getString(i); sb.append("\n").append(field).append(" = ").append(value); } if (sb.length() > 1) { String text = sb.substring(1); textView.setText(text); } else { textView.setText(" - nv - "); } textView.setTextColor(context.getResources().getColor(R.color.main_text_color)); textView.setPadding(5, 5, 5, 5); }
From source file:com.lee.sdk.utils.Utils.java
/** * ?????????//from ww w. j a v a 2s. co m * * @param context {@link Context} * @param shortcutName ?? * @param packageName ?? * @param uri {@link Uri} * * @return ???DB?true */ private static boolean hasShortcut(Context context, String shortcutName, String packageName, Uri uri) { if (context == null || TextUtils.isEmpty(shortcutName) || TextUtils.isEmpty(packageName) || uri == null) { return true; } boolean res = false; Cursor cursor = null; try { cursor = context.getContentResolver().query(uri, new String[] { "title", "intent" }, "title=?", new String[] { shortcutName }, null); if (cursor != null && cursor.moveToFirst()) { int index = cursor.getColumnIndex("intent"); if (index >= 0 && index < cursor.getColumnCount()) { do { String intentString = cursor.getString(index); if (intentString != null && intentString.contains(packageName)) { res = true; break; } } while (cursor.moveToNext()); } } } catch (Exception e) { res = true; } finally { if (cursor != null) { cursor.close(); cursor = null; } } return res; }
From source file:com.amaze.carbonfilemanager.activities.DbViewer.java
private ArrayList<String> getDbTableNames(Cursor c) { ArrayList<String> result = new ArrayList<>(); for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { for (int i = 0; i < c.getColumnCount(); i++) { result.add(c.getString(i));/*from w ww . j a v a 2 s. c om*/ } } return result; }
From source file:edu.asu.bscs.csiebler.waypointdatabase.MainActivity.java
private JSONArray getJsonResults() { JSONArray resultSet = new JSONArray(); try {//from w w w . j a va 2 s . co m WaypointDB db = new WaypointDB(this); db.copyDB(); SQLiteDatabase waypointDB = db.openDB(); waypointDB.beginTransaction(); String searchQuery = "SELECT * FROM waypoint"; Cursor cursor = waypointDB.rawQuery(searchQuery, null); cursor.moveToFirst(); while (cursor.isAfterLast() == false) { int totalColumn = cursor.getColumnCount(); JSONObject rowObject = new JSONObject(); for (int i = 0; i < totalColumn; i++) { if (cursor.getColumnName(i) != null) { try { if (cursor.getString(i) != null) { Log.d("TAG_NAME", cursor.getString(i)); rowObject.put(cursor.getColumnName(i), cursor.getString(i)); } else { rowObject.put(cursor.getColumnName(i), ""); } } catch (Exception e) { Log.d("TAG_NAME", e.getMessage()); } } } resultSet.put(rowObject); cursor.moveToNext(); } cursor.close(); waypointDB.endTransaction(); waypointDB.close(); db.close(); Log.d("TAG_NAME", resultSet.toString()); } catch (Exception ex) { Log.w(getClass().getSimpleName(), "Exception creating adapter: " + ex.getMessage()); } return resultSet; }
From source file:org.egov.android.data.SQLiteHelper.java
public JSONArray query(String sql) { JSONArray data = new JSONArray(); JSONObject row = null;/*w w w . j av a 2 s . c o m*/ Cursor cursor = query(sql, null); cursor.moveToFirst(); while (!cursor.isAfterLast()) { row = new JSONObject(); int cc = cursor.getColumnCount(); for (int i = 0; i < cc; i++) { try { row.put(cursor.getColumnName(i), cursor.getString(i)); } catch (JSONException e) { e.printStackTrace(); } } data.put(row); cursor.moveToNext(); } cursor.close(); return data.length() == 0 ? null : data; }
From source file:com.amaze.filemanager.activities.DbViewer.java
private ArrayList<String> getDbTableNames(Cursor c) { ArrayList<String> result = new ArrayList<String>(); for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { for (int i = 0; i < c.getColumnCount(); i++) { result.add(c.getString(i));/* ww w . j a v a 2s . co m*/ } } return result; }
From source file:ch.eitchnet.android.mabea.activity.SettingsFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { Logger.i(TAG, "onLoadFinished", data.getColumnCount() + ", " + data.getCount()); this.rootView.setVisibility(View.VISIBLE); if (data.getCount() == 0) { Logger.i(TAG, "onLoadFinished", "Loaded unpersisted setting to context."); Setting setting = MabeaApplication.getContext().getSetting(); setting.setPersisted(false);//from www. j a v a 2 s . co m return; } data.moveToFirst(); Setting setting = MabeaApplication.getContext().getSetting(); setting.setPersisted(true); int columnIndex; columnIndex = data.getColumnIndex(SettingsTable.COLUMN_ID); setting.setId(data.getInt(columnIndex)); columnIndex = data.getColumnIndex(SettingsTable.COLUMN_NAME); setting.setName(data.getString(columnIndex)); columnIndex = data.getColumnIndex(SettingsTable.COLUMN_URL); setting.setUrl(data.getString(columnIndex)); columnIndex = data.getColumnIndex(SettingsTable.COLUMN_USERNAME); setting.setUsername(data.getString(columnIndex)); Logger.i(TAG, "onLoadFinished", "Loaded persisted setting to context."); updateUi(); }
From source file:org.disrupted.rumble.database.statistics.StatisticDatabase.java
public JSONArray getJSON() { SQLiteDatabase database = databaseHelper.getReadableDatabase(); Cursor cursor = database.query(getTableName(), null, null, null, null, null, null); if (cursor == null) return null; JSONArray resultSet = new JSONArray(); try {/*from ww w . j av a2s .c om*/ cursor.moveToFirst(); while (cursor.isAfterLast() == false) { int totalColumn = cursor.getColumnCount(); JSONObject rowObject = new JSONObject(); for (int i = 0; i < totalColumn; i++) { if (cursor.getColumnName(i) != null) { try { if (cursor.getString(i) != null) rowObject.put(cursor.getColumnName(i), cursor.getString(i)); else rowObject.put(cursor.getColumnName(i), ""); } catch (Exception e) { } } } resultSet.put(rowObject); cursor.moveToNext(); } cursor.close(); } finally { cursor.close(); } return resultSet; }
From source file:com.facebook.stetho.inspector.protocol.module.Database.java
/** * Flatten all columns and all rows of a cursor to a single array. The array cannot be * interpreted meaningfully without the number of columns. * * @param cursor/*ww w .ja va 2s .c o m*/ * @param limit Maximum number of rows to process. * @return List of Java primitives matching the value type of each column. */ private List<Object> flattenRows(Cursor cursor, int limit) { Util.throwIfNot(limit >= 0); List<Object> flatList = new ArrayList<Object>(); final int numColumns = cursor.getColumnCount(); for (int row = 0; row < limit && cursor.moveToNext(); row++) { for (int column = 0; column < numColumns; column++) { switch (cursor.getType(column)) { case Cursor.FIELD_TYPE_NULL: flatList.add(null); break; case Cursor.FIELD_TYPE_INTEGER: flatList.add(cursor.getLong(column)); break; case Cursor.FIELD_TYPE_FLOAT: flatList.add(cursor.getDouble(column)); break; case Cursor.FIELD_TYPE_BLOB: flatList.add(cursor.getBlob(column)); break; case Cursor.FIELD_TYPE_STRING: default: flatList.add(cursor.getString(column)); break; } } } if (!cursor.isAfterLast()) { for (int column = 0; column < numColumns; column++) { flatList.add("{truncated}"); } } return flatList; }