Reputation: 67
I Want to get text of a row of a column in SQLite. For example I want to get text of tenth row in the column named title
. In other word I want to get tenth row text of title
column. How to do it? Please help me. thank-you.
Here is my sample code:
final SQLiteDatabase mydb = new
MyDatabase(EndicActivity.this).getWritableDatabase();
final Cursor c = mydb.rawQuery("select * from conteudos", null);
Upvotes: 1
Views: 219
Reputation: 356
You can achieve this in your own query by using the table's Id key if you know/have it:
final Cursor c = mydb.rawQuery("select * from conteudos where id = " + idYouWant, null);
Or simply by using limit and offset as in:
final Cursor c = mydb.rawQuery("select * from conteudos limit 1 offset 9", null);
The code above will return you the tenth row, you can use it for the nth row you want.
Upvotes: 0
Reputation: 164064
You can do it with moveToPosition(9)
:
final SQLiteDatabase mydb = new MyDatabase(EndicActivity.this).getWritableDatabase();
final Cursor c = mydb.rawQuery("select * from conteudos", null);
String title = "";
if (c.getCount() >= 10) {
c.moveToPosition(9);
title = c.getString(c.getColumnIndex("title"));
}
Upvotes: 2