//当点击Random和NextTORandom按钮的Onclick时如何使用cursor.moveToPosition(x)进行迭代?
//这是我的 Mydatabase.java 代码。该文件用于从数据库中获取单行。
public Cursor getData(int _id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor =db.rawQuery("Select * from '"+DB_TABLE+"' where _id = ?", new String[] { String.valueOf(_id)});
if (cursor != null)
{
cursor.moveToFirst();
}
return cursor;
// 这是我的 MyActivity.java 代码
public void onClick(View v) {
cur=db.getData(position);
int firstpos=1;
int lastpos=4;
switch(v.getId())
{
case R.id.NextToRandom :
{
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();
}
if(cur.moveToPosition(lastpos))
{
cur.moveToPosition(firstpos);
textView1.setText(""+cur.getString(1));
}
/*else
{
cur.moveToPosition(position);
textView1.setText(""+cur.getString(1));
position++;
}*/
//display details code
}
break;
case R.id.random:
{
Random r = new Random();
int rnum = r.nextInt(max - min + 1) + min;
cur=db.getData(rnum);
setNewData(rnum);
}
}
}
private void setNewData (int xyz) {
}
//我想通过单击 Random_back_button、Random_button 和 Random_Next_button 来遍历所有记录。如何实施?