也是Android Cursor.moveToNext()文档正确? [英] Is Android Cursor.moveToNext() Documentation Correct?

查看:879
本文介绍了也是Android Cursor.moveToNext()文档正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

布尔android.database.Cursor.moveToNext()文件说:

boolean android.database.Cursor.moveToNext() documentation says:

<一个href="http://developer.android.com/reference/android/database/Cursor.html#moveToNext%28%29">http://developer.android.com/reference/android/database/Cursor.html#moveToNext%28%29

将光标移动到下一行。

此方法将返回false,如果光标已经过去,在结果集中的最后一项。

This method will return false if the cursor is already past the last entry in the result set.

不过,我的书上说要做到以下几点提取游标数据:

However, my book says to do the following to extract data from a cursor:


Cursor myCursor = myDatabase.query(...);
if (myCursor.moveToFirst()) {
    do {
    int value = myCursor.getInt(VALUE_COL);
    // use value
    } while (myCursor.moveToNext());
}


谁是对的?这些既不可能是真的。如果您看不到的矛盾,想象myCursor已经从查询返回1行。要调用getInt第一次调用()将工作,但后来使用MoveToNext()将返回true,因为它不是已经是过去在结果中的最后一项设置。所以,现在的光标将过去的最后一个条目,并调用getInt第二次调用()会做一些不确定的。


Who's right? These both can't be true. If you can't see the contradiction, imagine myCursor has 1 row returned from the query. The first call to getInt() will work, but then moveToNext() will return true because it is not "already" past the last entry in the result set. So now the cursor will be past the last entry and the second call to getInt() will do something undefined.

我怀疑的文件是错误的,而应改为:

I suspect the documentation is wrong and should instead read:

此方法将返回false如果光标已经在在结果集中的最后一项。

This method will return false if the cursor is "already at" the last entry in the result set.

必须光标是已经过去(而不是AT)之前使用MoveToNext()方法返回假的最后一项?

Must the cursor be already PAST (not AT) the last entry before the moveToNext() method returns false?

没有蛇鲨请

推荐答案

逐字从API:

返回:       是否移动了成功。

Returns: whether the move succeeded.

因此​​,这意味着:

光标在第一行 - >使用MoveToNext() - >光标在第二行 - >没有第二行 - >返回false

如果你想详细信息,请访问源:<一href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.3.3_r1/android/database/AbstractCursor.java#AbstractCursor.moveToNext%28%29">http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.3.3_r1/android/database/AbstractCursor.java#AbstractCursor.moveToNext%28%29

If you want the details, go to the source: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.3.3_r1/android/database/AbstractCursor.java#AbstractCursor.moveToNext%28%29

public final boolean moveToNext() {
  return moveToPosition(mPos + 1);
}

public final boolean moveToPosition(int position) {
    // Make sure position isn't past the end of the cursor
    final int count = getCount();
    if (position >= count) {
        mPos = count;
        return false;
    }

这篇关于也是Android Cursor.moveToNext()文档正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆