Questions tagged [android-cursor]

android-cursor is an interface which provides random read-write access to the result set returned by a database query.

android-cursor is an interface which provides random read-write access to the result set returned by a database query.

Cursor provides a way to process data returned from a database, and provide features such as traversing the table, getting a certain row or column, and getting number of rows returned by the database.

It also allows to monitor a URI for changes using the setNotificationUri function, which tells that the data which the cursor has is old and it has to be updated.

Cursor Class Reference

1112 questions
304
votes
10 answers

What's the best way to iterate an Android Cursor?

I frequently see code which involves iterating over the result of a database query, doing something with each row, and then moving on to the next row. Typical examples are as follows. Cursor cursor = db.rawQuery(...); cursor.moveToFirst(); while…
Graham Borland
  • 60,055
  • 21
  • 138
  • 179
79
votes
7 answers

What is use of Cursor in Android Development?

I was going through some of code on the internet regarding the database connection, retrieval. I saw Cursor cur1= moveToFirst() in a lot of code and I want to know what the use of a cursor is and why we use moveToFirst().
Rithesh M
  • 1,287
  • 1
  • 12
  • 23
54
votes
2 answers

Using String[] selectionArgs in SQLiteDatabase.query()

How do I use the String[] selectionArgs in SQLiteDatabase.query()? I wish I could just set it to null, as I have no use for it. I am just trying to load an entire unsorted table from a database into a Cursor. Any suggestions on how to achieve this?
BenjiWiebe
  • 2,116
  • 5
  • 22
  • 41
45
votes
3 answers

android java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow

I am developing an application which download some files and save their text in file_content field to database. The file sizes can vary from some KBs to 10 MB. The app works for all sizes while saving. The problem occurs when using select statement…
Khawar Raza
  • 15,870
  • 24
  • 70
  • 127
43
votes
3 answers

Create a cursor from hardcoded array instead of DB

I am trying to make a drag-and-drop list for a little game app I am writing. There are 6 entries in the list. However the library I added required a Cursor object that talks to a DB. This is overkill for my situation. Is there a way to create a…
ddoor
  • 5,819
  • 9
  • 34
  • 41
42
votes
5 answers

Is it OK to have one instance of SQLiteOpenHelper shared by all Activities in an Android application?

Would it be OK to have a single instance of SQLiteOpenHelper as a member of a subclassed Application, and have all Activities that need an instance of SQLiteDatabase get it from the one helper?
Julian A.
  • 10,928
  • 16
  • 67
  • 107
36
votes
3 answers

Android Studio - Value must be ≥ 0

I am getting an error in Android Studio to do with my Cursor. I have the following line in my code String data = cursor.getString(cursor.getColumnIndex(columnIndex)); columnIndex is being passed into the method. This part…
Justin
  • 363
  • 1
  • 3
  • 5
36
votes
5 answers

How can I create a list Array with the cursor data in Android

How can I create a list Array (the list display First Alphabet when scroll) with the cursor data?
Dennie
  • 2,621
  • 13
  • 42
  • 41
34
votes
4 answers

Android Cursor with ORMLite to use in CursorAdapter

Is there any way to get Cursor for a query, which I am processing with ORMLite Dao object?
sealskej
  • 7,281
  • 12
  • 53
  • 64
34
votes
4 answers

POJO's versus Cursors in Android

I usually tend to define the model layer of my apps using POJO's, such as Article, Comment, etc. I was about to implement an AlphabetIndexer in the adapter of one of my ListViews. Right now this adapter accepts a Collection of Articles, which I…
benvd
  • 5,776
  • 5
  • 39
  • 59
34
votes
5 answers

How to disable cursor positioning and text selection in an EditText? (Android)

I'm searching for a way to prevent the user from moving the cursor position anywhere. The cursor should always stay at the end of the current EditText value. In addition to that the user should not be able to select anything in the EditText. Do you…
Louis
  • 2,140
  • 4
  • 19
  • 18
33
votes
9 answers

Finalizing a Cursor that has not been deactivated or closed non-fatal error

i'm getting a "Finalizing a Cursor that has not been deactivated or closed" error on this piece of code. The code is used to fill a listview. Since it's a non-fatal error , there is no crash and all seems to works fine..but i don't like the…
arnold
  • 455
  • 1
  • 8
  • 19
31
votes
4 answers

Difference between ContentObserver and DatasetObserver?

What is difference between ContentObserver and DatasetObserver? When one or another should be used? I get Cursor with single row. I want to be notified about data changes - eg. when row is updated. Which observer class should I register?
pixel
  • 24,905
  • 36
  • 149
  • 251
31
votes
5 answers

What does "invalid statement in fillWindow()" in Android cursor mean?

I sometimes see this error in my logcat output, Cursor: invalid statement in fillWindow(). It sometimes happens when I press the back key and then it goes to the default Android listview before going to my custom listview. What does it mean? How…
irobotxx
  • 5,963
  • 11
  • 62
  • 91
31
votes
2 answers

Android RecyclerView + CursorLoader + ContentProvider + "Load More"

I have created one Activity in that I am implementing CursorLoader for load data from Database. I have done that thing for all records of that Table but I want to load 30-30 records like Load More Functionality I have tried to create query and its…
1
2 3
74 75