public class CursorWindow
extends SQLiteClosable implements Parcelable
| java.lang.Object | ||
| android.database.sqlite.SQLiteClosable | ||
| android.database.CursorWindow | ||
包含多个游标行的缓冲区。
当初始创建并在本地使用时, CursorWindow是可读写的。 当发送到远程进程(通过将其写入到Parcel )时,远程进程会收到光标窗口的只读视图。 通常,光标窗口将由生产者分配,填充数据,然后发送给消费者阅读。
Inherited constants |
|---|
android.os.Parcelable
|
Fields |
|
|---|---|
public static final Creator<CursorWindow> |
CREATOR |
Public constructors |
|
|---|---|
CursorWindow(String name) 创建一个新的空游标窗口并给它一个名字。 |
|
CursorWindow(boolean localWindow) 此构造函数在API级别15中已弃用。本地和远程光标窗口之间不再有区别。 改为使用 |
|
公共方法(Public methods) |
|
|---|---|
boolean |
allocRow() 在此光标窗口的末尾分配一个新行。 |
void |
clear() 清除窗口的现有内容,使其可以安全地重新用于新数据。 |
void |
copyStringToBuffer(int row, int column, CharArrayBuffer buffer) 将指定行和列索引处的字段文本复制到 |
int |
describeContents() 描述此Parcelable实例的封送表示中包含的特殊对象的种类。 |
void |
freeLastRow() 释放此光标窗口中的最后一行。 |
byte[] |
getBlob(int row, int column) 获取指定行和列索引处字段的值作为字节数组。 |
double |
getDouble(int row, int column) 获取指定行和列索引处的字段值,其值为 |
float |
getFloat(int row, int column) 获取指定行和列索引处的字段值,其值为 |
int |
getInt(int row, int column) 获取指定行和列索引处的字段值,其值为 |
long |
getLong(int row, int column) 获取指定行和列索引处字段的值,作为 |
int |
getNumRows() 获取此窗口中的行数。 |
short |
getShort(int row, int column) 获取指定行和列索引处的字段值,其值为 |
int |
getStartPosition() 获取此光标窗口的起始位置。 |
String |
getString(int row, int column) 以字符串形式获取指定行和列索引处字段的值。 |
int |
getType(int row, int column) 返回指定行和列索引处字段的类型。 |
boolean |
isBlob(int row, int column) 此方法在API级别11中已弃用。请改为使用 |
boolean |
isFloat(int row, int column) 此方法在API级别11中已弃用。请改为使用 |
boolean |
isLong(int row, int column) 此方法在API级别11中已弃用。请改用 |
boolean |
isNull(int row, int column) 此方法在API级别11中已弃用。请改为使用 |
boolean |
isString(int row, int column) 此方法在API级别11中已弃用。请改为使用 |
static CursorWindow |
newFromParcel(Parcel p) |
boolean |
putBlob(byte[] value, int row, int column) 将字节数组复制到指定行和列索引处的字段中。 |
boolean |
putDouble(double value, int row, int column) 将双精度浮点值放入指定行和列索引处的字段中。 |
boolean |
putLong(long value, int row, int column) 在指定的行和列索引处将长整数放入字段中。 |
boolean |
putNull(int row, int column) 将空值放入指定行和列索引处的字段中。 |
boolean |
putString(String value, int row, int column) 将字符串复制到指定行和列索引处的字段中。 |
boolean |
setNumColumns(int columnNum) 设置此窗口中的列数。 |
void |
setStartPosition(int pos) 设置此光标窗口的起始位置。 |
String |
toString() 返回对象的字符串表示形式。 |
void |
writeToParcel(Parcel dest, int flags) 将此对象平铺到一个包裹中。 |
Protected methods |
|
|---|---|
void |
finalize() 当垃圾收集确定没有更多对该对象的引用时,由对象上的垃圾回收器调用。 |
void |
onAllReferencesReleased() 当通过调用 |
继承方法(Inherited methods) |
|
|---|---|
android.database.sqlite.SQLiteClosable
|
|
java.lang.Object
|
|
java.io.Closeable
|
|
android.os.Parcelable
|
|
java.lang.AutoCloseable
|
|
CursorWindow (String name)
创建一个新的空游标窗口并给它一个名字。
游标最初没有行或列。 在向光标添加任何行之前,请调用setNumColumns(int)以设置列数。
| 参数(Parameters) | |
|---|---|
name |
String: The name of the cursor window, or null if none. |
CursorWindow (boolean localWindow)
此构造函数在API级别15中已被弃用。
本地和远程光标窗口之间不再有区别。 改为使用CursorWindow(String)构造函数。
创建一个新的空白光标窗口。
游标最初没有行或列。 在向光标添加任何行之前调用setNumColumns(int)以设置列数。
| 参数(Parameters) | |
|---|---|
localWindow |
boolean: True if this window will be used in this process only, false if it might be sent to another processes. This argument is ignored. |
boolean allocRow ()
在此光标窗口的末尾分配一个新行。
| 返回(Returns) | |
|---|---|
boolean |
True if successful, false if the cursor window is out of memory. |
void clear ()
清除窗口的现有内容,使其可以安全地重新用于新数据。
开始位置( getStartPosition() ),行数( getNumRows() )以及游标中的列数都被重置为零。
void copyStringToBuffer (int row,
int column,
CharArrayBuffer buffer)
将指定的行和列索引中的字段文本复制到 CharArrayBuffer 。
缓冲区填充如下:
FIELD_TYPE_NULL, then the buffer is set to an empty string.FIELD_TYPE_STRING, then the buffer is set to the contents of the string.FIELD_TYPE_INTEGER, then the buffer is set to a string representation of the integer in decimal, obtained by formatting the value with the printf family of functions using format specifier %lld.FIELD_TYPE_FLOAT, then the buffer is set to a string representation of the floating-point value in decimal, obtained by formatting the value with the printf family of functions using format specifier %g.FIELD_TYPE_BLOB, then a SQLiteException is thrown.| 参数(Parameters) | |
|---|---|
row |
int: The zero-based row index. |
column |
int: The zero-based column index. |
buffer |
CharArrayBuffer: The CharArrayBuffer to hold the string. It is automatically resized if the requested string is larger than the buffer's current capacity. |
int describeContents ()
描述此Parcelable实例的封送表示中包含的特殊对象的种类。 例如,如果对象将在writeToParcel(Parcel, int)的输出中包含writeToParcel(Parcel, int) ,则此方法的返回值必须包含CONTENTS_FILE_DESCRIPTOR位。
| 返回(Returns) | |
|---|---|
int |
a bitmask indicating the set of special object types marshaled by this Parcelable object instance. |
byte[] getBlob (int row,
int column)
获取指定行和列索引处字段的值作为字节数组。
结果如下确定:
FIELD_TYPE_NULL, then the result is null.FIELD_TYPE_BLOB, then the result is the blob value.FIELD_TYPE_STRING, then the result is the array of bytes that make up the internal representation of the string value.FIELD_TYPE_INTEGER or FIELD_TYPE_FLOAT, then a SQLiteException is thrown.| 参数(Parameters) | |
|---|---|
row |
int: The zero-based row index. |
column |
int: The zero-based column index. |
| 返回(Returns) | |
|---|---|
byte[] |
The value of the field as a byte array. |
double getDouble (int row,
int column)
获取指定行和列索引处字段的值,作为 double 。
结果如下确定:
FIELD_TYPE_NULL, then the result is 0.0.FIELD_TYPE_STRING, then the result is the value obtained by parsing the string value with strtod. FIELD_TYPE_INTEGER, then the result is the integer value converted to a double.FIELD_TYPE_FLOAT, then the result is the double value.FIELD_TYPE_BLOB, then a SQLiteException is thrown.| 参数(Parameters) | |
|---|---|
row |
int: The zero-based row index. |
column |
int: The zero-based column index. |
| 返回(Returns) | |
|---|---|
double |
The value of the field as a double. |
float getFloat (int row,
int column)
获取指定行和列索引处的字段值,其值为 float 。
通过调用 getDouble(int, int)并将结果转换为 float来确定结果。
| 参数(Parameters) | |
|---|---|
row |
int: The zero-based row index. |
column |
int: The zero-based column index. |
| 返回(Returns) | |
|---|---|
float |
The value of the field as an float. |
int getInt (int row,
int column)
获取指定行和列索引处的字段值,其值为 int 。
通过调用 getLong(int, int)并将结果转换为 int来确定结果。
| 参数(Parameters) | |
|---|---|
row |
int: The zero-based row index. |
column |
int: The zero-based column index. |
| 返回(Returns) | |
|---|---|
int |
The value of the field as an int. |
long getLong (int row,
int column)
获取指定行和列索引处的字段值,其值为 long 。
结果如下确定:
FIELD_TYPE_NULL, then the result is 0L.FIELD_TYPE_STRING, then the result is the value obtained by parsing the string value with strtoll. FIELD_TYPE_INTEGER, then the result is the long value.FIELD_TYPE_FLOAT, then the result is the floating-point value converted to a long.FIELD_TYPE_BLOB, then a SQLiteException is thrown.| 参数(Parameters) | |
|---|---|
row |
int: The zero-based row index. |
column |
int: The zero-based column index. |
| 返回(Returns) | |
|---|---|
long |
The value of the field as a long. |
int getNumRows ()
获取此窗口中的行数。
| 返回(Returns) | |
|---|---|
int |
The number of rows in this cursor window. |
short getShort (int row,
int column)
获取指定行和列索引处的字段值,其值为 short 。
通过调用 getLong(int, int)并将结果转换为 short来确定结果。
| 参数(Parameters) | |
|---|---|
row |
int: The zero-based row index. |
column |
int: The zero-based column index. |
| 返回(Returns) | |
|---|---|
short |
The value of the field as a short. |
int getStartPosition ()
获取此光标窗口的起始位置。
起始位置是此窗口包含的第一行相对于 Cursor的整个结果集的 Cursor 。
| 返回(Returns) | |
|---|---|
int |
The zero-based start position. |
String getString (int row, int column)
以字符串形式获取指定行和列索引处字段的值。
结果如下确定:
FIELD_TYPE_NULL, then the result is null.FIELD_TYPE_STRING, then the result is the string value.FIELD_TYPE_INTEGER, then the result is a string representation of the integer in decimal, obtained by formatting the value with the printf family of functions using format specifier %lld.FIELD_TYPE_FLOAT, then the result is a string representation of the floating-point value in decimal, obtained by formatting the value with the printf family of functions using format specifier %g.FIELD_TYPE_BLOB, then a SQLiteException is thrown.| 参数(Parameters) | |
|---|---|
row |
int: The zero-based row index. |
column |
int: The zero-based column index. |
| 返回(Returns) | |
|---|---|
String |
The value of the field as a string. |
int getType (int row,
int column)
返回指定行和列索引处字段的类型。
返回的字段类型是:
| 参数(Parameters) | |
|---|---|
row |
int: The zero-based row index. |
column |
int: The zero-based column index. |
| 返回(Returns) | |
|---|---|
int |
The field type. |
boolean isBlob (int row,
int column)
此方法在API级别11中已弃用。
改为使用getType(int, int) 。
如果指定行和列索引处的字段的类型为 FIELD_TYPE_BLOB或 FIELD_TYPE_NULL则返回true。
| 参数(Parameters) | |
|---|---|
row |
int: The zero-based row index. |
column |
int: The zero-based column index. |
| 返回(Returns) | |
|---|---|
boolean |
True if the field has type FIELD_TYPE_BLOB or FIELD_TYPE_NULL. |
boolean isFloat (int row,
int column)
此方法在API级别11中已弃用。
改为使用getType(int, int) 。
如果指定的行和列索引处的字段的类型为 FIELD_TYPE_FLOAT ,则返回true。
| 参数(Parameters) | |
|---|---|
row |
int: The zero-based row index. |
column |
int: The zero-based column index. |
| 返回(Returns) | |
|---|---|
boolean |
True if the field has type FIELD_TYPE_FLOAT. |
boolean isLong (int row,
int column)
此方法在API级别11中已弃用。
改为使用getType(int, int) 。
如果指定的行和列索引处的字段的类型为 FIELD_TYPE_INTEGER ,则返回true。
| 参数(Parameters) | |
|---|---|
row |
int: The zero-based row index. |
column |
int: The zero-based column index. |
| 返回(Returns) | |
|---|---|
boolean |
True if the field has type FIELD_TYPE_INTEGER. |
boolean isNull (int row,
int column)
此方法在API级别11中已弃用。
改为使用getType(int, int) 。
如果指定行和列索引处的字段的类型为 FIELD_TYPE_NULL ,则返回true。
| 参数(Parameters) | |
|---|---|
row |
int: The zero-based row index. |
column |
int: The zero-based column index. |
| 返回(Returns) | |
|---|---|
boolean |
True if the field has type FIELD_TYPE_NULL. |
boolean isString (int row,
int column)
此方法在API级别11中已弃用。
改为使用getType(int, int) 。
如果指定的行和列索引处的字段的类型为 FIELD_TYPE_STRING或 FIELD_TYPE_NULL则返回true。
| 参数(Parameters) | |
|---|---|
row |
int: The zero-based row index. |
column |
int: The zero-based column index. |
| 返回(Returns) | |
|---|---|
boolean |
True if the field has type FIELD_TYPE_STRING or FIELD_TYPE_NULL. |
CursorWindow newFromParcel (Parcel p)
| 参数(Parameters) | |
|---|---|
p |
Parcel
|
| 返回(Returns) | |
|---|---|
CursorWindow |
|
boolean putBlob (byte[] value,
int row,
int column)
将字节数组复制到指定行和列索引处的字段中。
| 参数(Parameters) | |
|---|---|
value |
byte: The value to store. |
row |
int: The zero-based row index. |
column |
int: The zero-based column index. |
| 返回(Returns) | |
|---|---|
boolean |
True if successful. |
boolean putDouble (double value,
int row,
int column)
将双精度浮点值放入指定行和列索引处的字段中。
| 参数(Parameters) | |
|---|---|
value |
double: The value to store. |
row |
int: The zero-based row index. |
column |
int: The zero-based column index. |
| 返回(Returns) | |
|---|---|
boolean |
True if successful. |
boolean putLong (long value,
int row,
int column)
在指定的行和列索引处将长整数放入字段中。
| 参数(Parameters) | |
|---|---|
value |
long: The value to store. |
row |
int: The zero-based row index. |
column |
int: The zero-based column index. |
| 返回(Returns) | |
|---|---|
boolean |
True if successful. |
boolean putNull (int row,
int column)
将空值放入指定行和列索引处的字段中。
| 参数(Parameters) | |
|---|---|
row |
int: The zero-based row index. |
column |
int: The zero-based column index. |
| 返回(Returns) | |
|---|---|
boolean |
True if successful. |
boolean putString (String value, int row, int column)
将字符串复制到指定行和列索引处的字段中。
| 参数(Parameters) | |
|---|---|
value |
String: The value to store. |
row |
int: The zero-based row index. |
column |
int: The zero-based column index. |
| 返回(Returns) | |
|---|---|
boolean |
True if successful. |
boolean setNumColumns (int columnNum)
设置此窗口中的列数。
必须在将任何行添加到窗口之前调用此方法,否则如果列数与当前列数不同,则将无法设置列数。
| 参数(Parameters) | |
|---|---|
columnNum |
int: The new number of columns. |
| 返回(Returns) | |
|---|---|
boolean |
True if successful. |
void setStartPosition (int pos)
设置此光标窗口的起始位置。
起始位置是该窗口包含的第一行相对于 Cursor的整个结果集的 Cursor 。
| 参数(Parameters) | |
|---|---|
pos |
int: The new zero-based start position. |
String toString ()
返回对象的字符串表示形式。 通常, toString方法会返回一个“文本地表示”该对象的字符串。 结果应该是一个简洁但内容丰富的表述,对于一个人来说很容易阅读。 建议所有子类重写此方法。
类Object的toString方法返回一个字符串,其中包含对象为实例的类的名称,符号字符“ @ ”以及对象的哈希代码的无符号十六进制表示形式。 换句话说,这个方法返回一个字符串,其值等于:
getClass().getName() + '@' + Integer.toHexString(hashCode())
| 返回(Returns) | |
|---|---|
String |
a string representation of the object. |
void writeToParcel (Parcel dest, int flags)
将此对象平铺到一个包裹中。
| 参数(Parameters) | |
|---|---|
dest |
Parcel: The Parcel in which the object should be written. |
flags |
int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. |
void finalize ()
当垃圾收集确定没有更多对该对象的引用时,由对象上的垃圾回收器调用。 子类会覆盖finalize方法以处置系统资源或执行其他清理。
的常规协定finalize是,它被调用,如果当在Java TM虚拟机已确定不再有由该目的可以通过还没有死亡,除了作为一个动作的结果的任何线程访问的任何手段取决于某些其他可以完成的对象或类别的最终定稿。 finalize方法可以采取任何行动,包括使该对象再次可用于其他线程; 然而, finalize的通常目的是在对象被不可撤销地丢弃之前执行清理操作。 例如,表示输入/输出连接的对象的finalize方法可能会执行显式I / O事务,以在永久丢弃该对象之前中断连接。
类Object的finalize方法Object执行特殊操作; 它只是正常返回。 Object子类可能会覆盖此定义。
Java编程语言不保证哪个线程将为任何给定的对象调用finalize方法。 但是,保证调用finalize的线程在调用finalize时不会保留任何用户可见的同步锁。 如果finalize方法引发未捕获的异常,则忽略该异常,并终止该对象的终止。
在针对某个对象调用了 finalize方法之后,在Java虚拟机再次确定不再有任何方法可以通过尚未死亡的任何线程访问此对象,包括可能的操作通过准备完成的其他对象或类别,此时该对象可能被丢弃。
对于任何给定的对象,Java虚拟机永远不会多次调用 finalize方法。
由 finalize方法引发的任何异常 finalize导致终止此对象的终止,但会被忽略。
| 抛出异常(Throws) | |
|---|---|
Throwable |
|
void onAllReferencesReleased ()
当通过调用 releaseReference()或 close()释放对象的最后一个引用时调用。