一个Android光标怎么能在一个否定的态度? [英] How can an Android cursor be at a negative position?

查看:538
本文介绍了一个Android光标怎么能在一个否定的态度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在学习迭代光标,我learned我需要先移动到位置-1,然后在循环中使用moveToNext

While learning to iterate over a cursor, I learned that I needed to first move to position "-1" and then use "moveToNext" in a loop:

cursor.moveToPosition(-1);
for (int i = 0; cursor.moveToNext(); i++) {
  //do something with the cursor
}

在数学上,这是有道理的,我不知道这意味着什么移动到光标到负位置。该文档只是说,它是有效的,doesn't似乎在说如何使用它。

While mathematically this makes sense, I don't know what it means to move to a cursor to a negative position. The documentation just says it's valid–doesn't seem to say how it's used.

难道这只能用来做迭代可能的,或者是有其他的用例的位置-1?

Is this used ONLY to make iteration possible, or is there other use cases for the position -1?

推荐答案

一个光标不应该在负位置,光标数据在这就是为什么你总是需要获得前将光标移动到第一个位置的位置0开始使用数据

A cursor should not be at a negative position, a cursors data starts at position 0 which is why you always need to move the cursor to the first position before getting the data using

if(cursor.moveToFirst()){
    //you have data in the cursor
}

现在要经过光标只是简单地用一个do / while循环

now to go through the cursor just simply use a do/while loop

do{
    //process cursor data
}while(cursor.moveToNext);

您与您的for循环打破了converntion,如果你将光标移动到第一的位置,然后尝试执行你的for循环光标将尝试移动到下一个位置,你甚至处理第一位置之前在做什么。这就是为什么你不进入for循环,当你的光标有1东西

what you are doing with your for loop breaks that converntion, if you move your cursor to the first position then try executing your for loop the cursor will try to move to the next position before you even process the first position. This is why you dont enter the for loop when you have 1 thing in the cursor

这篇关于一个Android光标怎么能在一个否定的态度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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