Add Value To ContentValues - Android Database

Android examples for Database:ContentValues

Description

Add Value To ContentValues

Demo Code


//package com.java2s;
import android.content.ContentValues;

public class Main {
    public static void AddToContentValues(ContentValues collection,
            String keyName, Object objectToAdd) {
        Class objectType = objectToAdd.getClass();

        if (objectType.equals(int.class))
            collection.put(keyName, (int) objectToAdd);
        else if (objectType.equals(String.class))
            collection.put(keyName, (String) objectToAdd);
        else if (objectType.equals(double.class))
            collection.put(keyName, (double) objectToAdd);
        else if (objectType.equals(long.class))
            collection.put(keyName, (long) objectToAdd);
        else if (objectType.equals(float.class))
            collection.put(keyName, (float) objectToAdd);
        else/*from w w  w  .  j a  v  a2  s .c  om*/
            collection.put(keyName, objectToAdd.toString());
    }
}

Related Tutorials