MergeCursor


public class MergeCursor
extends AbstractCursor

java.lang.Object
   ↳ android.database.AbstractCursor
     ↳ android.database.MergeCursor


A convenience class that lets you present an array of Cursors as a single linear Cursor. The schema of the cursors presented is entirely up to the creator of the MergeCursor, and may be different if that is desired. Calls to getColumns, getColumnIndex, etc will return the value for the row that the MergeCursor is currently pointing at.

Summary

Inherited constants

Inherited fields

Public constructors

MergeCursor(Cursor[] cursors)

Public methods

void close()

Closes the Cursor, releasing all of its resources and making it completely invalid.

void deactivate()

Deactivates the Cursor, making all calls on it fail until requery() is called.

byte[] getBlob(int column)

Returns the value of the requested column as a byte array.

String[] getColumnNames()

Returns a string array holding the names of all of the columns in the result set in the order in which they were listed in the result.

int getCount()

Returns the numbers of rows in the cursor.

double getDouble(int column)

Returns the value of the requested column as a double.

float getFloat(int column)

Returns the value of the requested column as a float.

int getInt(int column)

Returns the value of the requested column as an int.

long getLong(int column)

Returns the value of the requested column as a long.

short getShort(int column)

Returns the value of the requested column as a short.

String getString(int column)

Returns the value of the requested column as a String.

int getType(int column)

Returns data type of the given column's value.

boolean isNull(int column)

Returns true if the value in the indicated column is null.

boolean onMove(int oldPosition, int newPosition)

This function is called every time the cursor is successfully scrolled to a new position, giving the subclass a chance to update any state it may have.

void registerContentObserver(ContentObserver observer)

Register an observer that is called when changes happen to the content backing this cursor.

void registerDataSetObserver(DataSetObserver observer)

Register an observer that is called when changes happen to the contents of the this cursors data set, for example, when the data set is changed via requery(), deactivate(), or close().

boolean requery()

Performs the query that created the cursor again, refreshing its contents.

void unregisterContentObserver(ContentObserver observer)

Unregister an observer that has previously been registered with this cursor via registerContentObserver(ContentObserver).

void unregisterDataSetObserver(DataSetObserver observer)

Unregister an observer that has previously been registered with this cursor via registerContentObserver(ContentObserver).

Inherited methods

Public constructors

MergeCursor

Added in API level 1
public MergeCursor (Cursor[] cursors)

Parameters
cursors Cursor

Public methods

close

Added in API level 1
public void close ()

Closes the Cursor, releasing all of its resources and making it completely invalid. Unlike deactivate() a call to requery() will not make the Cursor valid again.

deactivate

Added in API level 1
public void deactivate ()

Deactivates the Cursor, making all calls on it fail until requery() is called. Inactive Cursors use fewer resources than active Cursors. Calling requery() will make the cursor active again.

getBlob

Added in API level 1
public byte[] getBlob (int column)

Returns the value of the requested column as a byte array.

The result and whether this method throws an exception when the column value is null or the column type is not a blob type is implementation-defined.

Parameters
column int: the zero-based index of the target column. Value is 0 or greater

Returns
byte[] the value of that column as a byte array.

getColumnNames

Added in API level 1
public String[] getColumnNames ()

Returns a string array holding the names of all of the columns in the result set in the order in which they were listed in the result.

Returns
String[] the names of the columns returned in this query.

getCount

Added in API level 1
public int getCount ()

Returns the numbers of rows in the cursor.

Returns
int the number of rows in the cursor. Value is 0 or greater

getDouble

Added in API level 1
public double getDouble (int column)

Returns the value of the requested column as a double.

The result and whether this method throws an exception when the column value is null, the column type is not a floating-point type, or the floating-point value is not representable as a double value is implementation-defined.

Parameters
column int: the zero-based index of the target column. Value is 0 or greater

Returns
double the value of that column as a double.

getFloat

Added in API level 1
public float getFloat (int column)

Returns the value of the requested column as a float.

The result and whether this method throws an exception when the column value is null, the column type is not a floating-point type, or the floating-point value is not representable as a float value is implementation-defined.

Parameters
column int: the zero-based index of the target column. Value is 0 or greater

Returns
float the value of that column as a float.

getInt

Added in API level 1
public int getInt (int column)

Returns the value of the requested column as an int.

The result and whether this method throws an exception when the column value is null, the column type is not an integral type, or the integer value is outside the range [Integer.MIN_VALUE, Integer.MAX_VALUE] is implementation-defined.

Parameters
column int: the zero-based index of the target column. Value is 0 or greater

Returns
int the value of that column as an int.

getLong

Added in API level 1
public long getLong (int column)

Returns the value of the requested column as a long.

The result and whether this method throws an exception when the column value is null, the column type is not an integral type, or the integer value is outside the range [Long.MIN_VALUE, Long.MAX_VALUE] is implementation-defined.

Parameters
column int: the zero-based index of the target column. Value is 0 or greater

Returns
long the value of that column as a long.

getShort

Added in API level 1
public short getShort (int column)

Returns the value of the requested column as a short.

The result and whether this method throws an exception when the column value is null, the column type is not an integral type, or the integer value is outside the range [Short.MIN_VALUE, Short.MAX_VALUE] is implementation-defined.

Parameters
column int: the zero-based index of the target column. Value is 0 or greater

Returns
short the value of that column as a short.

getString

Added in API level 1
public String getString (int column)

Returns the value of the requested column as a String.

The result and whether this method throws an exception when the column value is null or the column type is not a string type is implementation-defined.

Parameters
column int: the zero-based index of the target column. Value is 0 or greater

Returns
String the value of that column as a String.

getType

Added in API level 11
public int getType (int column)

Returns data type of the given column's value. The preferred type of the column is returned but the data may be converted to other types as documented in the get-type methods such as getInt(int), getFloat(int) etc.

Parameters
column int: the zero-based index of the target column. Value is 0 or greater

Returns
int column value type Value is FIELD_TYPE_NULL, FIELD_TYPE_INTEGER, FIELD_TYPE_FLOAT, FIELD_TYPE_STRING, or FIELD_TYPE_BLOB

isNull

Added in API level 1
public boolean isNull (int column)

Returns true if the value in the indicated column is null.

Parameters
column int: the zero-based index of the target column. Value is 0 or greater

Returns
boolean whether the column value is null.

onMove

Added in API level 1
public boolean onMove (int oldPosition, 
                int newPosition)

This function is called every time the cursor is successfully scrolled to a new position, giving the subclass a chance to update any state it may have. If it returns false the move function will also do so and the cursor will scroll to the beforeFirst position.

Parameters
oldPosition int: the position that we're moving from

newPosition int: the position that we're moving to

Returns
boolean true if the move is successful, false otherwise

registerContentObserver

Added in API level 1
public void registerContentObserver (ContentObserver observer)

Register an observer that is called when changes happen to the content backing this cursor. Typically the data set won't change until requery() is called.

Parameters
observer ContentObserver: the object that gets notified when the content backing the cursor changes.

registerDataSetObserver

Added in API level 1
public void registerDataSetObserver (DataSetObserver observer)

Register an observer that is called when changes happen to the contents of the this cursors data set, for example, when the data set is changed via requery(), deactivate(), or close().

Parameters
observer DataSetObserver: the object that gets notified when the cursors data set changes.

requery

Added in API level 1
public boolean requery ()

Performs the query that created the cursor again, refreshing its contents. This may be done at any time, including after a call to deactivate(). Since this method could execute a query on the database and potentially take a while, it could cause ANR if it is called on Main (UI) thread. A warning is printed if this method is being executed on Main thread.

Returns
boolean true if the requery succeeded, false if not, in which case the cursor becomes invalid.

unregisterContentObserver

Added in API level 1
public void unregisterContentObserver (ContentObserver observer)

Unregister an observer that has previously been registered with this cursor via registerContentObserver(ContentObserver).

Parameters
observer ContentObserver: the object to unregister.

unregisterDataSetObserver

Added in API level 1
public void unregisterDataSetObserver (DataSetObserver observer)

Unregister an observer that has previously been registered with this cursor via registerContentObserver(ContentObserver).

Parameters
observer DataSetObserver: the object to unregister.