本文整理汇总了Java中android.database.Cursor.getColumnCount方法的典型用法代码示例。如果您正苦于以下问题:Java Cursor.getColumnCount方法的具体用法?Java Cursor.getColumnCount怎么用?Java Cursor.getColumnCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.database.Cursor
的用法示例。
在下文中一共展示了Cursor.getColumnCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getExplainQueryPlan
import android.database.Cursor; //导入方法依赖的package包/类
private String[] getExplainQueryPlan() {
Cursor cursor = db.rawQuery("EXPLAIN QUERY PLAN " + query, queryArgs);
String[] plan = new String[cursor.getCount()];
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
// The docs at https://sqlite.org/eqp.html talk about how the output format of
// EXPLAIN QUERY PLAN can change between SQLite versions. This has been observed
// between the sqlite versions on Android 2.3.3 and Android 5.0. However, it seems
// that the last column is always the one with the interesting details that we wish
// to log. If this fails for some reason, then hey, it is only for debug builds, right?
if (cursor.getColumnCount() > 0) {
int index = cursor.getColumnCount() - 1;
plan[cursor.getPosition()] = cursor.getString(index);
}
cursor.moveToNext();
}
cursor.close();
return plan;
}
示例2: getVehicleAsJson
import android.database.Cursor; //导入方法依赖的package包/类
private static JSONObject getVehicleAsJson(final Long id, Context context) throws JSONException {
String[] selectionArgs = { String.valueOf(id) };
Cursor cursor = context.getContentResolver().query(VehicleEntry.CONTENT_URI,
FuelUpContract.ALL_COLUMNS_VEHICLES, VehicleEntry._ID + "=?",
selectionArgs, null);
JSONObject row = new JSONObject();
if (cursor != null) {
cursor.moveToFirst();
for (int i = 0; i < cursor.getColumnCount(); i++) {
if (cursor.getColumnName(i) != null
&& !cursor.getColumnName(i).equals(VehicleEntry._ID)
&& !cursor.getColumnName(i).equals(VehicleEntry.COLUMN_PICTURE)) {
row.put(cursor.getColumnName(i), cursor.getString(i));
}
}
cursor.close();
}
return row;
}
示例3: dump
import android.database.Cursor; //导入方法依赖的package包/类
public static void dump(Cursor cursor) {
if (cursor != null && !cursor.isClosed()) {
cursor.moveToFirst();
do {
int cc = cursor.getColumnCount();
Logger.e(" cursor: %s/%s", cc, cursor.toString());
for (int i = 0; i < cc; i++) {
Logger.e(" %s: %s", cursor.getColumnName(i),
cursor.getString(i));
}
} while (cursor.moveToNext());
cursor.moveToFirst();
}
}
示例4: getJsonArrayFromCursor
import android.database.Cursor; //导入方法依赖的package包/类
private static JSONArray getJsonArrayFromCursor(final Cursor cursor) {
JSONArray resultSet = new JSONArray();
if (cursor != null) {
while (cursor.moveToNext()) {
JSONObject row = new JSONObject();
for (int i = 0; i < cursor.getColumnCount(); i++) {
if (cursor.getColumnName(i) != null
&& !cursor.getColumnName(i).equals(ExpenseEntry.COLUMN_VEHICLE)
&& !cursor.getColumnName(i).equals(FillUpEntry.COLUMN_VEHICLE)
&& !cursor.getColumnName(i).equals(BaseColumns._ID)) {
try {
row.put(cursor.getColumnName(i), cursor.getString(i));
} catch (Exception e) {
Log.d(LOG_TAG, e.getMessage());
}
}
}
resultSet.put(row);
}
cursor.close();
}
return resultSet;
}
示例5: getTableData
import android.database.Cursor; //导入方法依赖的package包/类
@NonNull
public Table getTableData(SQLiteDatabase database, String tableName) {
Table table = new Table();
Cursor tableDataCursor = database.rawQuery("SELECT * FROM " + tableName, null);
table.setColumns(Arrays.asList(tableDataCursor.getColumnNames()));
List<Row> rows = new ArrayList<>();
if (tableDataCursor != null && tableDataCursor.moveToFirst()) {
int columnCount = tableDataCursor.getColumnCount();
while (!tableDataCursor.isAfterLast()) {
List<String> data = new ArrayList<>();
for (int i = 0; i < columnCount; i++) {
data.add(tableDataCursor.getString(i));
}
Row row = new Row(data);
rows.add(row);
tableDataCursor.moveToNext();
}
}
table.setName(tableName);
table.setRows(rows);
tableDataCursor.close();
return table;
}
示例6: getMusicInfo
import android.database.Cursor; //导入方法依赖的package包/类
public ArrayList<String> getMusicInfo(int id) {
if (id == -1) {
return null;
}
Cursor cursor = null;
ArrayList<String> musicInfo = new ArrayList<String>();
cursor = db.query(DatabaseHelper.MUSIC_TABLE, null, ID_COLUMN + " = ?", new String[]{"" + id}, null, null, null);
if (cursor.moveToFirst()) {
for (int i = 0; i < cursor.getColumnCount(); i++) {
musicInfo.add(i, cursor.getString(i));
}
} else {
musicInfo.add("0");
musicInfo.add("听听音乐");
musicInfo.add("好音质");
musicInfo.add("0");
musicInfo.add("0");
musicInfo.add("0");
musicInfo.add("0");
musicInfo.add("0");
}
if (cursor != null) {
cursor.close();
}
return musicInfo;
}
示例7: getBookmarksFromContentUri
import android.database.Cursor; //导入方法依赖的package包/类
@NonNull
private List<HistoryItem> getBookmarksFromContentUri(String contentUri) {
List<HistoryItem> list = new ArrayList<>();
Cursor cursor = getBrowserCursor(contentUri);
try {
if (cursor != null) {
for (int n = 0; n < cursor.getColumnCount(); n++) {
Log.d(TAG, cursor.getColumnName(n));
}
while (cursor.moveToNext()) {
if (cursor.getInt(2) == 1) {
String url = cursor.getString(0);
String title = cursor.getString(1);
if (url.isEmpty()) {
continue;
}
if (title == null || title.isEmpty()) {
title = Utils.getDomainName(url);
}
if (title != null) {
list.add(new HistoryItem(url, title));
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
Utils.close(cursor);
return list;
}
示例8: getDbModel
import android.database.Cursor; //导入方法依赖的package包/类
public static DbModel getDbModel(final Cursor cursor) {
DbModel result = new DbModel();
int columnCount = cursor.getColumnCount();
for (int i = 0; i < columnCount; i++) {
result.add(cursor.getColumnName(i), cursor.getString(i));
}
return result;
}
示例9: copyData
import android.database.Cursor; //导入方法依赖的package包/类
/** copies data from Android's media db to ours */
private static int copyData (ContentResolver cr, String minId) {
int imported = 0;
String where = WHERE_ALL;
String[] whereArgs = null;
if (minId != null) {
where = WHERE_MIN_ID;
whereArgs = new String[] { minId };
}
Cursor allFiles = CustomCursor.wrap(cr.query(MediaStore.Files.getContentUri("external"),
FILES_PROJECTION, where, whereArgs, BaseColumns._ID));
if (allFiles != null) {
int count = allFiles.getCount();
int ccount = allFiles.getColumnCount();
if (count > 0) {
// transaction size limited, acts like buffered output stream and auto-flushes queue
BulkInserter inserter = new BulkInserter(MusicStoreInternal.FILES_IMPORT, cr, 2000);
if (DBG) Log.d(TAG, "found items to import:" + count);
while (allFiles.moveToNext()) {
ContentValues cv = new ContentValues(ccount);
DatabaseUtils.cursorRowToContentValues(allFiles, cv);
inserter.add(cv);
}
imported = inserter.execute();
}
allFiles.close();
}
return imported;
}
示例10: getContactsCursor
import android.database.Cursor; //导入方法依赖的package包/类
private Cursor getContactsCursor(ContentResolver cr) {
String req = "(" + Data.MIMETYPE + " = '" + CommonDataKinds.Phone.CONTENT_ITEM_TYPE
+ "' AND " + CommonDataKinds.Phone.NUMBER + " IS NOT NULL "
+ " OR (" + Data.MIMETYPE + " = '" + CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE
+ "' AND " + CommonDataKinds.SipAddress.SIP_ADDRESS + " IS NOT NULL))";
String[] projection = new String[] { Data.CONTACT_ID, Data.DISPLAY_NAME };
String query = Data.DISPLAY_NAME + " IS NOT NULL AND (" + req + ")";
Cursor cursor = cr.query(Data.CONTENT_URI, projection, query, null, " lower(" + Data.DISPLAY_NAME + ") COLLATE UNICODE ASC");
if (cursor == null) {
return cursor;
}
MatrixCursor result = new MatrixCursor(cursor.getColumnNames());
Set<String> groupBy = new HashSet<String>();
while (cursor.moveToNext()) {
String name = cursor.getString(cursor.getColumnIndex(Data.DISPLAY_NAME));
if (!groupBy.contains(name)) {
groupBy.add(name);
Object[] newRow = new Object[cursor.getColumnCount()];
int contactID = cursor.getColumnIndex(Data.CONTACT_ID);
int displayName = cursor.getColumnIndex(Data.DISPLAY_NAME);
newRow[contactID] = cursor.getString(contactID);
newRow[displayName] = cursor.getString(displayName);
result.addRow(newRow);
}
}
cursor.close();
return result;
}
示例11: caseEnergyUseBill
import android.database.Cursor; //导入方法依赖的package包/类
@Test
public void caseEnergyUseBill() {
// 16/ 02 ate 20/03
Context context = InstrumentationRegistry.getTargetContext();
ContentResolver contentResolver = context.getContentResolver();
Calendar dateBegin = Calendar.getInstance();
//Utilização de energia no dia 01/01/2015.
dateBegin.set(2016, 11, 22, 0, 0, 0);
dateBegin.set(Calendar.MILLISECOND, 0);
Calendar dateEnd = Calendar.getInstance();
//Utilização de energia no dia 01/01/2015.
dateEnd.set(2016, 12, 21, 0, 0, 0);
dateEnd.set(Calendar.MILLISECOND, 0);
ContentValues contentValues = EnergyUseBillEntry.parse("February 2017", dateBegin.getTime(), dateEnd.getTime(), 0.65);
contentResolver.insert(OhaEnergyUseContract.CONTENT_URI_BILL, contentValues);
Cursor cursorBills = contentResolver.query(
OhaEnergyUseContract.CONTENT_URI_BILL,
null,
null,
null,
null
);
String tag = "Energy Bill:";
while (cursorBills.moveToNext()){
Log.i(tag,String.format("==============%s================", cursorBills.getString(1)));
for(int field = 0; field < cursorBills.getColumnCount(); field++ ){
Log.i(tag,String.format("%s: %s", cursorBills.getColumnName(field), cursorBills.getString(field) ) );
}
}
}
示例12: handlePickBack
import android.database.Cursor; //导入方法依赖的package包/类
private void handlePickBack(Context con, Intent intent) {
Uri uri = intent.getData();
Cursor cursor = con.getContentResolver().query(uri, null, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
HashMap<String, String> map = new HashMap<String, String>();
for (int i = 0; i < cursor.getColumnCount(); i++) {
map.put(cursor.getColumnName(i), cursor.getString(i));
}
String spath = map.get("_data");
decodeFile(spath, dWidth, dQuality);
cursor.close();
}
}
示例13: InstalledApp
import android.database.Cursor; //导入方法依赖的package包/类
public InstalledApp(Cursor cursor) {
checkCursorPosition(cursor);
for (int i = 0; i < cursor.getColumnCount(); i++) {
String n = cursor.getColumnName(i);
switch (n) {
case Schema.InstalledAppTable.Cols._ID:
id = cursor.getLong(i);
break;
case Schema.InstalledAppTable.Cols.Package.NAME:
packageName = cursor.getString(i);
break;
case Schema.InstalledAppTable.Cols.VERSION_CODE:
versionCode = cursor.getInt(i);
break;
case Schema.InstalledAppTable.Cols.VERSION_NAME:
versionName = cursor.getString(i);
break;
case Schema.InstalledAppTable.Cols.APPLICATION_LABEL:
applicationLabel = cursor.getString(i);
break;
case Schema.InstalledAppTable.Cols.SIGNATURE:
signature = cursor.getString(i);
break;
case Schema.InstalledAppTable.Cols.LAST_UPDATE_TIME:
lastUpdateTime = cursor.getLong(i);
break;
case Schema.InstalledAppTable.Cols.HASH_TYPE:
hashType = cursor.getString(i);
break;
case Schema.InstalledAppTable.Cols.HASH:
hash = cursor.getString(i);
break;
}
}
}
示例14: getAlbumArt
import android.database.Cursor; //导入方法依赖的package包/类
private String getAlbumArt(Context mcontext, int album_id) {
String mUriAlbums = "content://media/external/audio/albums";
String[] projection = new String[]{"album_art"};
Cursor cur = mcontext.getContentResolver().query(
Uri.parse(mUriAlbums + File.separator + Integer.toString(album_id)),
projection, null, null, null);
String album_art = null;
if (cur.getCount() > 0 && cur.getColumnCount() > 0) {
cur.moveToNext();
album_art = cur.getString(0);
}
cur.close();
return album_art;
}
示例15: cursor2Map
import android.database.Cursor; //导入方法依赖的package包/类
public static Map<String, Object> cursor2Map(Cursor cursor) {
Map<String, Object> map = new HashMap<>();
if (cursor != null && cursor.getColumnCount() > 0) {
int count = cursor.getColumnCount();
for (int i = 0; i < count; i++) {
int type = cursor.getType(i);
Object value = null;
switch (type) {
case Cursor.FIELD_TYPE_STRING:
value = cursor.getString(i);
break;
case Cursor.FIELD_TYPE_INTEGER:
value = cursor.getInt(i);
break;
case Cursor.FIELD_TYPE_FLOAT:
value = cursor.getFloat(i);
break;
case Cursor.FIELD_TYPE_NULL:
LogUtils.d("未知的参数类型,type:" + type);
break;
case Cursor.FIELD_TYPE_BLOB:
LogUtils.d("未知的参数类型,type:" + type);
break;
}
if (value != null) {
String name = cursor.getColumnName(i);
map.put(name, value);
}
}
}
return map;
}