本文整理汇总了Java中android.content.ContentValues.getAsDouble方法的典型用法代码示例。如果您正苦于以下问题:Java ContentValues.getAsDouble方法的具体用法?Java ContentValues.getAsDouble怎么用?Java ContentValues.getAsDouble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.ContentValues
的用法示例。
在下文中一共展示了ContentValues.getAsDouble方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateExpenseAndUpdate
import android.content.ContentValues; //导入方法依赖的package包/类
private int validateExpenseAndUpdate(final Uri uri, final ContentValues contentValues, long id) {
if (contentValues.containsKey(ExpenseEntry.COLUMN_INFO)) {
String info = contentValues.getAsString(ExpenseEntry.COLUMN_INFO).trim();
if (info.isEmpty()) {
throw new IllegalArgumentException("Expense info must be set.");
}
}
if (contentValues.containsKey(ExpenseEntry.COLUMN_PRICE)) {
Double price = contentValues.getAsDouble(ExpenseEntry.COLUMN_PRICE);
if (price == null || price < 0) {
throw new IllegalArgumentException("Wrong price " + price);
}
}
if (contentValues.containsKey(ExpenseEntry.COLUMN_VEHICLE)) {
Long vehicleId = contentValues.getAsLong(ExpenseEntry.COLUMN_VEHICLE);
String selectionVehicle = VehicleEntry._ID + "=?";
String[] selectionVehicleArgs = new String[] { String.valueOf(vehicleId) };
Cursor cursor = mDbHelper.getReadableDatabase().query(VehicleEntry.TABLE_NAME, FuelUpContract.ALL_COLUMNS_VEHICLES, selectionVehicle, selectionVehicleArgs, null, null, null);
if (cursor == null || cursor.getCount() != 1) {
if (cursor != null)
cursor.close();
throw new IllegalArgumentException("Vehicle with id=" + vehicleId + " does not exist.");
}
cursor.close();
}
final String selection = ExpenseEntry._ID + "=?";
final String[] idArgument = new String[] { String.valueOf(id) };
getContext().getContentResolver().notifyChange(uri, null);
return mDbHelper.getWritableDatabase().update(
ExpenseEntry.TABLE_NAME, contentValues, selection, idArgument);
}
示例2: validateExpenseAndInsert
import android.content.ContentValues; //导入方法依赖的package包/类
private Uri validateExpenseAndInsert(Uri uri, ContentValues contentValues) {
String info = contentValues.getAsString(ExpenseEntry.COLUMN_INFO).trim();
if (info.isEmpty()) {
throw new IllegalArgumentException("Expense info must be set.");
}
Double price = contentValues.getAsDouble(ExpenseEntry.COLUMN_PRICE);
if (price == null || price < 0) {
throw new IllegalArgumentException("Wrong price " + price);
}
Long vehicleId = contentValues.getAsLong(ExpenseEntry.COLUMN_VEHICLE);
String selection = VehicleEntry._ID + "=?";
String[] selectionArgs = new String[] { String.valueOf(vehicleId) };
Cursor cursor = mDbHelper.getReadableDatabase().query(VehicleEntry.TABLE_NAME, FuelUpContract.ALL_COLUMNS_VEHICLES, selection, selectionArgs, null, null, null);
if (cursor == null || cursor.getCount() != 1) {
if (cursor != null)
cursor.close();
throw new IllegalArgumentException("Vehicle with id=" + vehicleId + " does not exist.");
}
cursor.close();
SQLiteDatabase database = mDbHelper.getWritableDatabase();
long id = database.insert(ExpenseEntry.TABLE_NAME, null, contentValues);
if (id == -1) {
Log.e(LOG_TAG, "Failed to insert row for " + uri);
return null;
}
getContext().getContentResolver().notifyChange(uri, null);
return ContentUris.withAppendedId(uri, id);
}
示例3: setContent
import android.content.ContentValues; //导入方法依赖的package包/类
public void setContent(ContentValues cv) {
id = cv.getAsString("ID");
name = cv.getAsString("Name");
lat = cv.getAsDouble("Lat");
lon = cv.getAsDouble("Lon");
}