Example usage for android.database DatabaseUtils cursorDoubleToCursorValues

List of usage examples for android.database DatabaseUtils cursorDoubleToCursorValues

Introduction

In this page you can find the example usage for android.database DatabaseUtils cursorDoubleToCursorValues.

Prototype

public static void cursorDoubleToCursorValues(Cursor cursor, String field, ContentValues values) 

Source Link

Document

Reads a Double out of a field in a Cursor and writes it to a Map.

Usage

From source file:com.money.manager.ex.common.AllDataListFragment.java

private Money getTotalFromCursor(Cursor cursor) {
    Money total = MoneyFactory.fromString("0");
    int originalPosition = cursor.getPosition();
    AllDataAdapter adapter = getAllDataAdapter();
    CurrencyService currencyService = new CurrencyService(getContext());
    int baseCurrencyId = currencyService.getBaseCurrencyId();
    ContentValues values = new ContentValues();

    int currencyId;
    Money amount;/* w w w.  j  a v  a2s  .  c  o  m*/
    Money converted;
    String transType;
    TransactionTypes transactionType;

    cursor.moveToPosition(Constants.NOT_SET);

    while (cursor.moveToNext()) {
        values.clear();

        // Read needed data.
        DatabaseUtils.cursorStringToContentValues(cursor, adapter.TRANSACTIONTYPE, values);
        DatabaseUtils.cursorIntToContentValues(cursor, adapter.CURRENCYID, values);
        DatabaseUtils.cursorIntToContentValues(cursor, adapter.TOCURRENCYID, values);
        DatabaseUtils.cursorDoubleToCursorValues(cursor, adapter.AMOUNT, values);
        DatabaseUtils.cursorDoubleToCursorValues(cursor, adapter.TOAMOUNT, values);

        transType = values.getAsString(adapter.TRANSACTIONTYPE);
        transactionType = TransactionTypes.valueOf(transType);

        if (transactionType.equals(TransactionTypes.Transfer)) {
            currencyId = values.getAsInteger(adapter.TOCURRENCYID);
            amount = MoneyFactory.fromString(values.getAsString(adapter.TOAMOUNT));
        } else {
            currencyId = values.getAsInteger(adapter.CURRENCYID);
            amount = MoneyFactory.fromString(values.getAsString(adapter.AMOUNT));
        }

        converted = currencyService.doCurrencyExchange(baseCurrencyId, amount, currencyId);
        total = total.add(converted);
    }

    cursor.moveToPosition(originalPosition);

    return total;
}