获取所选数字行,并将其返回为Integer格式



我应该如何实现到getRow2()来获得选定的行数?我可以输入movetopposition (x);

MainActivity.java如下:

Database db = new Database(this);
int x = db.getRow2();
Cursor cursor = db.getName();
cursor.moveToPosition(x);
tvName.setText(cursor.getString(0));

Database.java如下:

public int getRow2(){
SQLiteDatabase db = this.getReadableDatabase();
int rows = -1;
try {
rows = (int) db.compileStatement("SELECT COUNT(*) FROM " + TBL_USER).simpleQueryForLong();
} catch (NullPointerException e) {
return -1;
}
return rows;
}

public Cursor getName(){
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("select name from TBL_USER",null);
return cursor;
}

已解决:使用moveToNext()代替movetopposition ()多么简单的问题😚

最新更新