2013-07-29 74 views
0

//这不起作用。它显示第一条记录并在此之后停止。我想要一个循环,即使在最后一个记录后仍然保持运行。我收到了你点光标开始形式位置0
//代码android.database.CursorIndexOutOfBoundsException:请求索引1,大小为1

cur=db.getData(position); 

    switch(v.getId()) 
    { 

    case R.id.next : 
    { 

     if (cur != null && cur.getCount()> 0 && position < cur.getCount() && position != cur.getCount()){ 
      cur.moveToPosition(position); 
      textView1.setText(""+cur.getString(1));// Display Columns 
      position++; 
      cur.moveToNext(); 
     } 
} 

//我想一个循环来显示记录编号

为下一个按钮 如:

1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 

后退按钮 例如:

5 4 3 2 1 5 4 3 2 1 

随机按钮 如:

3 4 5 1 
5 1 2 3 
4 5 1 2 
+0

我想要通过一个使用光标的位置来获取记录之一。我不想用。 – user2438323

+0

这个例外只是第一次出现?记住索引从0开始 – Tobiel

回答

0
if (cur != null && cur.getCount()> 0 && position < cur.getCount() && position != cur.getCount()){ 
         cur.moveToPosition(position); 
         textView1.setText(""+cur.getString(1));// Display Columns 
        } 
+0

还要确保你的游标有多于或等于1列。如果你想访问第一列然后cur.getString(0)。在光标中,索引从0开始。谢谢, –

5

似乎是个例外,因为你正在试图让不存在的位置的对象。记得在0

直接从DOCS指数开始:

public abstract boolean moveToPosition (int position) 

在API级别1

将光标移动到一个绝对位置。值的有效范围是-1 < =位置< =计数。

如果请求目标可达,则此方法将返回true,否则返回false。 参数 定位要移动到的基于零的位置。 返回

whether the requested move fully succeeded. 
0

呼叫之前获得的数据增量的位置,因为你正试图在unexisting到acceed元素我是你的分贝。

cur =db. getData(position) ; 

然后

position++; 

记住要首先声明位置= 0

相关问题