to top
Android APIs
public final class

ContentValues

extends Object
implements Parcelable
java.lang.Object
   ↳ android.content.ContentValues

Class Overview

This class is used to store a set of values that the ContentResolver can process.

Summary

Constants
String TAG
[Expand]
Inherited Constants
From interface android.os.Parcelable
Fields
public static final Creator<ContentValues> CREATOR
Public Constructors
ContentValues()
Creates an empty set of values using the default initial size
ContentValues(int size)
Creates an empty set of values using the given initial size
ContentValues(ContentValues from)
Creates a set of values copied from the given set
Public Methods
void clear()
Removes all values.
boolean containsKey(String key)
Returns true if this object has the named value.
int describeContents()
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
boolean equals(Object object)
Compares this instance with the specified object and indicates if they are equal.
Object get(String key)
Gets a value.
Boolean getAsBoolean(String key)
Gets a value and converts it to a Boolean.
Byte getAsByte(String key)
Gets a value and converts it to a Byte.
byte[] getAsByteArray(String key)
Gets a value that is a byte array.
Double getAsDouble(String key)
Gets a value and converts it to a Double.
Float getAsFloat(String key)
Gets a value and converts it to a Float.
Integer getAsInteger(String key)
Gets a value and converts it to an Integer.
Long getAsLong(String key)
Gets a value and converts it to a Long.
Short getAsShort(String key)
Gets a value and converts it to a Short.
String getAsString(String key)
Gets a value and converts it to a String.
int hashCode()
Returns an integer hash code for this object.
Set<String> keySet()
Returns a set of all of the keys
void put(String key, Byte value)
Adds a value to the set.
void put(String key, Integer value)
Adds a value to the set.
void put(String key, Float value)
Adds a value to the set.
void put(String key, Short value)
Adds a value to the set.
void put(String key, byte[] value)
Adds a value to the set.
void put(String key, String value)
Adds a value to the set.
void put(String key, Double value)
Adds a value to the set.
void put(String key, Long value)
Adds a value to the set.
void put(String key, Boolean value)
Adds a value to the set.
void putAll(ContentValues other)
Adds all values from the passed in ContentValues.
void putNull(String key)
Adds a null value to the set.
void remove(String key)
Remove a single value.
int size()
Returns the number of values.
String toString()
Returns a string containing a concise, human-readable description of this object.
Set<Entry<StringObject>> valueSet()
Returns a set of all of the keys and values
void writeToParcel(Parcel parcel, int flags)
Flatten this object in to a Parcel.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable

Constants

public static final String TAG

Added in API level 1

Constant Value: "ContentValues"

Fields

public static final Creator<ContentValues> CREATOR

Added in API level 1

Public Constructors

public ContentValues ()

Added in API level 1

Creates an empty set of values using the default initial size

public ContentValues (int size)

Added in API level 1

Creates an empty set of values using the given initial size

Parameters
size the initial size of the set of values

public ContentValues (ContentValues from)

Added in API level 1

Creates a set of values copied from the given set

Parameters
from the values to copy

Public Methods

public void clear ()

Added in API level 1

Removes all values.

public boolean containsKey (String key)

Added in API level 1

Returns true if this object has the named value.

Parameters
key the value to check for
Returns
  • true if the value is present, false otherwise

public int describeContents ()

Added in API level 1

Describe the kinds of special objects contained in this Parcelable's marshalled representation.

Returns
  • a bitmask indicating the set of special object types marshalled by the Parcelable.

public boolean equals (Object object)

Added in API level 1

Compares this instance with the specified object and indicates if they are equal. In order to be equal, o must represent the same object as this instance using a class-specific comparison. The general contract is that this comparison should be reflexive, symmetric, and transitive. Also, no object reference other than null is equal to null.

The default implementation returns true only if this == o. See Writing a correct equals method if you intend implementing your own equals method.

The general contract for the equals and hashCode() methods is that if equals returns true for any two objects, then hashCode() must return the same value for these objects. This means that subclasses of Object usually override either both methods or neither of them.

Parameters
object the object to compare this instance with.
Returns
  • true if the specified object is equal to this Object; false otherwise.

public Object get (String key)

Added in API level 1

Gets a value. Valid value types are String, Boolean, and Number implementations.

Parameters
key the value to get
Returns
  • the data for the value

public Boolean getAsBoolean (String key)

Added in API level 1

Gets a value and converts it to a Boolean.

Parameters
key the value to get
Returns
  • the Boolean value, or null if the value is missing or cannot be converted

public Byte getAsByte (String key)

Added in API level 1

Gets a value and converts it to a Byte.

Parameters
key the value to get
Returns
  • the Byte value, or null if the value is missing or cannot be converted

public byte[] getAsByteArray (String key)

Added in API level 1

Gets a value that is a byte array. Note that this method will not convert any other types to byte arrays.

Parameters
key the value to get
Returns
  • the byte[] value, or null is the value is missing or not a byte[]

public Double getAsDouble (String key)

Added in API level 1

Gets a value and converts it to a Double.

Parameters
key the value to get
Returns
  • the Double value, or null if the value is missing or cannot be converted

public Float getAsFloat (String key)

Added in API level 1

Gets a value and converts it to a Float.

Parameters
key the value to get
Returns
  • the Float value, or null if the value is missing or cannot be converted

public Integer getAsInteger (String key)

Added in API level 1

Gets a value and converts it to an Integer.

Parameters
key the value to get
Returns
  • the Integer value, or null if the value is missing or cannot be converted

public Long getAsLong (String key)

Added in API level 1

Gets a value and converts it to a Long.

Parameters
key the value to get
Returns
  • the Long value, or null if the value is missing or cannot be converted

public Short getAsShort (String key)

Added in API level 1

Gets a value and converts it to a Short.

Parameters
key the value to get
Returns
  • the Short value, or null if the value is missing or cannot be converted

public String getAsString (String key)

Added in API level 1

Gets a value and converts it to a String.

Parameters
key the value to get
Returns
  • the String for the value

public int hashCode ()

Added in API level 1

Returns an integer hash code for this object. By contract, any two objects for which equals(Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

Note that hash values must not change over time unless information used in equals comparisons also changes.

See Writing a correct hashCode method if you intend implementing your own hashCode method.

Returns
  • this object's hash code.

public Set<String> keySet ()

Added in API level 11

Returns a set of all of the keys

Returns
  • a set of all of the keys

public void put (String key, Byte value)

Added in API level 1

Adds a value to the set.

Parameters
key the name of the value to put
value the data for the value to put

public void put (String key, Integer value)

Added in API level 1

Adds a value to the set.

Parameters
key the name of the value to put
value the data for the value to put

public void put (String key, Float value)

Added in API level 1

Adds a value to the set.

Parameters
key the name of the value to put
value the data for the value to put

public void put (String key, Short value)

Added in API level 1

Adds a value to the set.

Parameters
key the name of the value to put
value the data for the value to put

public void put (String key, byte[] value)

Added in API level 1

Adds a value to the set.

Parameters
key the name of the value to put
value the data for the value to put

public void put (String key, String value)

Added in API level 1

Adds a value to the set.

Parameters
key the name of the value to put
value the data for the value to put

public void put (String key, Double value)

Added in API level 1

Adds a value to the set.

Parameters
key the name of the value to put
value the data for the value to put

public void put (String key, Long value)

Added in API level 1

Adds a value to the set.

Parameters
key the name of the value to put
value the data for the value to put

public void put (String key, Boolean value)

Added in API level 1

Adds a value to the set.

Parameters
key the name of the value to put
value the data for the value to put

public void putAll (ContentValues other)

Added in API level 1

Adds all values from the passed in ContentValues.

Parameters
other the ContentValues from which to copy

public void putNull (String key)

Added in API level 1

Adds a null value to the set.

Parameters
key the name of the value to make null

public void remove (String key)

Added in API level 1

Remove a single value.

Parameters
key the name of the value to remove

public int size ()

Added in API level 1

Returns the number of values.

Returns
  • the number of values

public String toString ()

Added in API level 1

Returns a string containing a concise, human-readable description of this object.

Returns
  • a printable representation of this object.

public Set<Entry<StringObject>> valueSet ()

Added in API level 1

Returns a set of all of the keys and values

Returns
  • a set of all of the keys and values

public void writeToParcel (Parcel parcel, int flags)

Added in API level 1

Flatten this object in to a Parcel.

Parameters
parcel The Parcel in which the object should be written.
flags Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.