当前位置: 首页>>代码示例>>Java>>正文


Java Cursor.getColumnCount方法代码示例

本文整理汇总了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;
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:20,代码来源:LoggingQuery.java

示例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;
}
 
开发者ID:piskula,项目名称:FuelUp,代码行数:22,代码来源:JsonUtil.java

示例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();
    }

}
 
开发者ID:NamTranDev,项目名称:CleanArchitechture,代码行数:18,代码来源:Logger.java

示例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;
}
 
开发者ID:piskula,项目名称:FuelUp,代码行数:25,代码来源:JsonUtil.java

示例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;
}
 
开发者ID:jainsahab,项目名称:AndroidSnooper,代码行数:27,代码来源:DatabaseDataReader.java

示例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;
}
 
开发者ID:lijunyandev,项目名称:MeetMusic,代码行数:27,代码来源:DBManager.java

示例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;
}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:33,代码来源:BookmarkLocalSync.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:CursorUtils.java

示例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;
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:30,代码来源:MusicStoreImportImpl.java

示例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;
}
 
开发者ID:treasure-lau,项目名称:Linphone4Android,代码行数:34,代码来源:ContactsManager.java

示例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) ) );
        }
    }
}
 
开发者ID:brolam,项目名称:OpenHomeAnalysis,代码行数:34,代码来源:OhaEnergyUseProviderTest.java

示例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();
    }
}
 
开发者ID:quickhybrid,项目名称:quickhybrid-android,代码行数:15,代码来源:PhotoSelector.java

示例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;
            }
        }
    }
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:38,代码来源:InstalledApp.java

示例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;
}
 
开发者ID:fikyair,项目名称:musicplayer,代码行数:15,代码来源:MusicListTransit.java

示例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;
}
 
开发者ID:jessie345,项目名称:RetrofitAppArchitecture,代码行数:34,代码来源:Utils.java


注:本文中的android.database.Cursor.getColumnCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。