當前位置: 首頁>>代碼示例>>Java>>正文


Java Cursor.getType方法代碼示例

本文整理匯總了Java中android.database.Cursor.getType方法的典型用法代碼示例。如果您正苦於以下問題:Java Cursor.getType方法的具體用法?Java Cursor.getType怎麽用?Java Cursor.getType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.database.Cursor的用法示例。


在下文中一共展示了Cursor.getType方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: insertItemToSheet

import android.database.Cursor; //導入方法依賴的package包/類
private void insertItemToSheet(String table, HSSFSheet sheet, ArrayList<String> columns) {
    HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
    Cursor cursor = database.rawQuery("select * from " + table, null);
    cursor.moveToFirst();
    int n = 1;
    while (!cursor.isAfterLast()) {
        HSSFRow rowA = sheet.createRow(n);
        for (int j = 0; j < columns.size(); j++) {
            HSSFCell cellA = rowA.createCell(j);
            if (cursor.getType(j) == Cursor.FIELD_TYPE_BLOB) {
                HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) j, n, (short) (j + 1), n + 1);
                anchor.setAnchorType(3);
                patriarch.createPicture(anchor, workbook.addPicture(cursor.getBlob(j), HSSFWorkbook.PICTURE_TYPE_JPEG));
            } else {
                cellA.setCellValue(new HSSFRichTextString(cursor.getString(j)));
            }
        }
        n++;
        cursor.moveToNext();
    }
    cursor.close();
}
 
開發者ID:androidmads,項目名稱:SQLite2XL,代碼行數:23,代碼來源:SQLiteToExcel.java

示例2: ListRow

import android.database.Cursor; //導入方法依賴的package包/類
public ListRow(OModel model, Cursor cursor) {
    this.baseModel = model;
    for (String column : cursor.getColumnNames()) {
        int index = cursor.getColumnIndex(column);
        switch (cursor.getType(index)) {
            case Cursor.FIELD_TYPE_INTEGER:
                put(column, cursor.getInt(index));
                break;
            case Cursor.FIELD_TYPE_BLOB:
                put(column, cursor.getBlob(index));
                break;
            case Cursor.FIELD_TYPE_STRING:
                put(column, cursor.getString(index));
                break;
            case Cursor.FIELD_TYPE_FLOAT:
                put(column, cursor.getFloat(index));
                break;
            case Cursor.FIELD_TYPE_NULL:
                put(column, false);
                break;
        }
    }
}
 
開發者ID:odoo-mobile-intern,項目名稱:odoo-work,代碼行數:24,代碼來源:ListRow.java

示例3: _dumpColumns

import android.database.Cursor; //導入方法依賴的package包/類
private void _dumpColumns(Cursor cursor, String msg) {
	String[] columns = new String[cursor.getColumnCount()];
	for (int i = 0; i < cursor.getColumnCount(); i++)
		switch (cursor.getType(i)) {
		case Cursor.FIELD_TYPE_NULL:
			columns[i] = null;
			break;
		case Cursor.FIELD_TYPE_INTEGER:
			columns[i] = Integer.toString(cursor.getInt(i));
			break;
		case Cursor.FIELD_TYPE_FLOAT:
			columns[i] = Float.toString(cursor.getFloat(i));
			break;
		case Cursor.FIELD_TYPE_STRING:
			columns[i] = cursor.getString(i);
			break;
		case Cursor.FIELD_TYPE_BLOB:
			columns[i] = "[blob]";
			break;
		default:
			Util.log(this, Log.WARN, "Unknown cursor data type=" + cursor.getType(i));
		}
	Util.log(this, Log.WARN, TextUtils.join(", ", columns) + " " + msg);
}
 
開發者ID:ukanth,項目名稱:XPrivacy,代碼行數:25,代碼來源:XContentResolver.java

示例4: getData1

import android.database.Cursor; //導入方法依賴的package包/類
/**
 * 根據MIMETYPE類型, 返回對應聯係人的data1字段的數據
 */
private static List<String> getData1(final ContentResolver contentResolver, String contactId, final String mimeType) {
    List<String> dataList = new ArrayList<>();

    Cursor dataCursor = contentResolver.query(ContactsContract.Data.CONTENT_URI,
            new String[]{ContactsContract.Data.DATA1},
            ContactsContract.Data.CONTACT_ID + "=?" + " AND "
                    + ContactsContract.Data.MIMETYPE + "='" + mimeType + "'",
            new String[]{String.valueOf(contactId)}, null);
    if (dataCursor != null) {
        if (dataCursor.getCount() > 0) {
            if (dataCursor.moveToFirst()) {
                do {
                    final int columnIndex = dataCursor.getColumnIndex(ContactsContract.Data.DATA1);
                    final int type = dataCursor.getType(columnIndex);
                    if (type == FIELD_TYPE_STRING) {
                        final String data = dataCursor.getString(columnIndex);
                        if (!TextUtils.isEmpty(data)) {
                            dataList.add(data);
                        }
                    }
                } while (dataCursor.moveToNext());
            }
        }
        dataCursor.close();
    }

    return dataList;
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:32,代碼來源:ContactsPickerHelper.java

示例5: getType

import android.database.Cursor; //導入方法依賴的package包/類
private static int getType(Cursor cursor, int columnIndex) throws Exception
{

    if (Build.VERSION.SDK_INT >= 11)
    {
        return cursor.getType(columnIndex);
    }

    SQLiteCursor sqLiteCursor = (SQLiteCursor) cursor;
    CursorWindow cursorWindow = sqLiteCursor.getWindow();
    int pos = cursor.getPosition();
    int type = -1;
    if (cursorWindow.isNull(pos, columnIndex))
    {
        type = Cursor.FIELD_TYPE_NULL;
    } else if (cursorWindow.isLong(pos, columnIndex))
    {
        type = Cursor.FIELD_TYPE_INTEGER;
    } else if (cursorWindow.isFloat(pos, columnIndex))
    {
        type = Cursor.FIELD_TYPE_FLOAT;
    } else if (cursorWindow.isString(pos, columnIndex))
    {
        type = Cursor.FIELD_TYPE_STRING;
    } else if (cursorWindow.isBlob(pos, columnIndex))
    {
        type = Cursor.FIELD_TYPE_BLOB;
    }

    return type;
}
 
開發者ID:gzxishan,項目名稱:OftenPorter,代碼行數:32,代碼來源:TypeUtil.java

示例6: 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

示例7: getJsonFromCursor

import android.database.Cursor; //導入方法依賴的package包/類
private JSONObject getJsonFromCursor(Cursor cur) {
    JSONObject json = new JSONObject();

    int nCol = cur.getColumnCount();
    String[] keys = cur.getColumnNames();
    try {
        for (int j = 0; j < nCol; j++)
            switch (cur.getType(j)) {
                case 0:
                    json.put(keys[j], null);
                    break;
                case 1:
                    json.put(keys[j], cur.getLong(j));
                    break;
                case 2:
                    json.put(keys[j], cur.getFloat(j));
                    break;
                case 3:
                    json.put(keys[j], cur.getString(j));
                    break;
                case 4:
                    json.put(keys[j], cur.getBlob(j));
            }
    } catch (Exception e) {
        return null;
    }

    return json;
}
 
開發者ID:briankabiro,項目名稱:react-native-get-sms-android,代碼行數:30,代碼來源:SmsModule.java

示例8: copyColumns

import android.database.Cursor; //導入方法依賴的package包/類
private void copyColumns(Cursor cursor, MatrixCursor result, int count) {
	try {
		Object[] columns = new Object[count];
		for (int i = 0; i < count; i++)
			switch (cursor.getType(i)) {
			case Cursor.FIELD_TYPE_NULL:
				columns[i] = null;
				break;
			case Cursor.FIELD_TYPE_INTEGER:
				columns[i] = cursor.getInt(i);
				break;
			case Cursor.FIELD_TYPE_FLOAT:
				columns[i] = cursor.getFloat(i);
				break;
			case Cursor.FIELD_TYPE_STRING:
				columns[i] = cursor.getString(i);
				break;
			case Cursor.FIELD_TYPE_BLOB:
				columns[i] = cursor.getBlob(i);
				break;
			default:
				Util.log(this, Log.WARN, "Unknown cursor data type=" + cursor.getType(i));
			}
		result.addRow(columns);
	} catch (Throwable ex) {
		Util.bug(this, ex);
	}
}
 
開發者ID:ukanth,項目名稱:XPrivacy,代碼行數:29,代碼來源:XContentResolver.java

示例9: log

import android.database.Cursor; //導入方法依賴的package包/類
private static void log(final Cursor cursor) {
    if (cursor != null) {
        if (cursor.getCount() > 0) {
            L.e("----------------------start--------------------");
            L.i("數量:" + cursor.getCount() + " 列數:" + cursor.getColumnCount());
            if (cursor.moveToFirst()) {
                do {
                    for (int i = 0; i < cursor.getColumnCount(); i++) {
                        final String columnName = cursor.getColumnName(i);
                        final int columnIndex = cursor.getColumnIndex(columnName);
                        final int type = cursor.getType(columnIndex);
                        String data = "", ty = "";
                        if (type == Cursor.FIELD_TYPE_NULL) {
                            ty = "NULL";
                            data = "空值";
                        } else if (type == Cursor.FIELD_TYPE_BLOB) {
                            ty = "BLOB";
                            final byte[] bytes = cursor.getBlob(columnIndex);
                            data = String.valueOf(bytes) + " " + bytes.length * 1f / 1024f + "KB";
                        } else if (type == Cursor.FIELD_TYPE_FLOAT) {
                            ty = "FLOAT";
                            data = String.valueOf(cursor.getFloat(columnIndex));
                        } else if (type == Cursor.FIELD_TYPE_INTEGER) {
                            ty = "INTEGER";
                            data = String.valueOf(cursor.getInt(columnIndex));
                        } else if (type == FIELD_TYPE_STRING) {
                            ty = "STRING";
                            data = cursor.getString(columnIndex);
                        }

                        L.i("第" + i + "列->名稱:" + columnName + " 索引:" + columnIndex + " 類型:" + ty + " 值:" + data);
                    }
                } while (cursor.moveToNext());
            }
            L.e("------------------------end---------------------");
        }
        cursor.close();
    }
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:40,代碼來源:ContactsPickerHelper.java

示例10: dumpCursor

import android.database.Cursor; //導入方法依賴的package包/類
/**
 * Useful for debugging during development, so that arbitrary queries can be made, and their
 * results inspected in the debugger.
 */
@SuppressWarnings("unused")
@RequiresApi(api = 11)
public static List<Map<String, String>> dumpCursor(Cursor cursor) {
    List<Map<String, String>> data = new ArrayList<>();

    if (cursor == null) {
        return data;
    }

    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        Map<String, String> row = new HashMap<>(cursor.getColumnCount());
        for (String col : cursor.getColumnNames()) {
            int i = cursor.getColumnIndex(col);
            switch (cursor.getType(i)) {
                case Cursor.FIELD_TYPE_NULL:
                    row.put(col, null);
                    break;

                case Cursor.FIELD_TYPE_INTEGER:
                    row.put(col, Integer.toString(cursor.getInt(i)));
                    break;

                case Cursor.FIELD_TYPE_FLOAT:
                    row.put(col, Double.toString(cursor.getFloat(i)));
                    break;

                case Cursor.FIELD_TYPE_STRING:
                    row.put(col, cursor.getString(i));
                    break;

                case Cursor.FIELD_TYPE_BLOB:
                    row.put(col, new String(cursor.getBlob(i), Charset.defaultCharset()));
                    break;
            }
        }
        data.add(row);
        cursor.moveToNext();
    }

    cursor.close();
    return data;
}
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:48,代碼來源:Utils.java

示例11: processCollectedSensorData

import android.database.Cursor; //導入方法依賴的package包/類
@WorkerThread
void processCollectedSensorData() throws JSONException {
    if (mPublisher == null || !mPublisher.isReady()) {
        return;
    }

    // Query the data we wish to push to the cloud
    long lastSyndId = DatalogDbHelper.getLastSyncId(this);
    Cursor cursor = mDatabase.query(DatalogDbHelper.TABLE_NAME,
            null,
            DatalogDbHelper.DatalogEntry._ID + " > " + lastSyndId,
            null,
            null,
            null,
            BaseColumns._ID + " ASC");
    Log.i(TAG, "publishing " + cursor.getCount() + " log entries");

    final int columnCount = cursor.getColumnCount();
    for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
        JSONObject entryObject = new JSONObject();
        // Add the device ID to the JSON record.
        //
        // FIXME: There should be a way to get Google Cloud IOT to do this on its
        // end, so I don't need to trust the IDs.
        entryObject.put("deviceId", mDeviceId);
        long id = 0;
        for (int i = 0; i < columnCount; i++) {
            String columnName = cursor.getColumnName(i);
            if (columnName != null) {
                // Note the most recent ID we've transmitted, but don't include
                // the ID column in the JSON message
                if (columnName.equals(BaseColumns._ID)) {
                    id = cursor.getLong(i);
                    continue;
                }
                if (cursor.getType(i) == Cursor.FIELD_TYPE_FLOAT) {
                    entryObject.put(columnName, cursor.getDouble(i));
                } else {
                    entryObject.put(columnName, cursor.getString(i));
                }
            }
        }
        // Push message to the cloud
        mPublisher.publish(entryObject.toString());
        Log.d(TAG, "Sent entry: " + (cursor.getPosition()+1) + "/" +
                cursor.getCount());
        if (id > lastSyndId)
            DatalogDbHelper.setLastSyncId(this, id);
    }
    cursor.close();
}
 
開發者ID:jpuderer,項目名稱:Taxi-Datalogger,代碼行數:52,代碼來源:CloudPublisherService.java

示例12: query

import android.database.Cursor; //導入方法依賴的package包/類
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
        String sortOrder) {
    Uri fileUri = getFileUriWhenReady(uri);
    if (fileUri == null) return null;

    // Workaround for a bad assumption that particular MediaStore columns exist by certain third
    // party applications.
    // http://crbug.com/467423.
    Cursor source = super.query(fileUri, projection, selection, selectionArgs, sortOrder);

    String[] columnNames = source.getColumnNames();
    String[] newColumnNames = columnNamesWithData(columnNames);
    if (columnNames == newColumnNames) return source;

    MatrixCursor cursor = new MatrixCursor(newColumnNames, source.getCount());

    source.moveToPosition(-1);
    while (source.moveToNext()) {
        MatrixCursor.RowBuilder row = cursor.newRow();
        for (int i = 0; i < columnNames.length; i++) {
            switch (source.getType(i)) {
                case Cursor.FIELD_TYPE_INTEGER:
                    row.add(source.getInt(i));
                    break;
                case Cursor.FIELD_TYPE_FLOAT:
                    row.add(source.getFloat(i));
                    break;
                case Cursor.FIELD_TYPE_STRING:
                    row.add(source.getString(i));
                    break;
                case Cursor.FIELD_TYPE_BLOB:
                    row.add(source.getBlob(i));
                    break;
                case Cursor.FIELD_TYPE_NULL:
                default:
                    row.add(null);
                    break;
            }
        }
    }

    source.close();
    return cursor;
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:46,代碼來源:ChromeFileProvider.java


注:本文中的android.database.Cursor.getType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。