Reputation: 761
// This is not working. It shows first record and stops after that. I want a loop that keep running even after the last record. I got your point that cursor starts form position 0.
//Code
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();
}
}
// I want a loop to display record number
for next button eg:
1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
back button eg:
5 4 3 2 1 5 4 3 2 1
random button eg:
3 4 5 1
5 1 2 3
4 5 1 2
Upvotes: 0
Views: 2545
Reputation: 2717
Call get data before increments position, that because you are trying to acceed an element in a unexisting I'm your db.
cur =db. getData(position) ;
Then
position++;
Remember to first of all declare position = 0
Upvotes: 0
Reputation: 1543
That exception appears, because you are trying to get the object in a position that do not exist. Remember index start at 0.
Direct from DOCS :
public abstract boolean moveToPosition (int position)
Added in API level 1
Move the cursor to an absolute position. The valid range of values is -1 <= position <= count.
This method will return true if the request destination was reachable, otherwise, it returns false. Parameters position the zero-based position to move to. Returns
whether the requested move fully succeeded.
Upvotes: 5
Reputation: 2850
if (cur != null && cur.getCount()> 0 && position < cur.getCount() && position != cur.getCount()){
cur.moveToPosition(position);
textView1.setText(""+cur.getString(1));// Display Columns
}
Upvotes: 0