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

878 questions
5
votes
2 answers

In Android SQLite, working directly with Cursor is more memory efficient than creating Model Objects?

In most of the Android sample codes, populating a ListView from SQLite database is done in two ways, Prefetch data to List - Execute query, create Model objects for each row then add it to a List and close the Cursor, then populate ListView with…
user4226071
5
votes
1 answer

Android: Add column to already populated Cursor

I'm confused about whether to use MergeCursor or CursorJoiner. I have a Cursor (A) with a load of data in it. Lets say there are 100 rows in Cursor (A) and 3 columns. What I want to do is insert (append) a new column to the Cursor so the resulting…
SparkyNZ
  • 5,336
  • 6
  • 33
  • 67
5
votes
0 answers

CalendarContract.Instances.query() searchQuery

I'm trying to determine whether a given event exists in the user's calendar, where equality is determined by start time, end time, title, and location all matching. The documentation says: public static final Cursor query (ContentResolver cr,…
user2152081
  • 507
  • 5
  • 14
5
votes
5 answers

Putting cursor data into an array

Being new in Android, I am having trouble dealing with the following: public String[] getContacts(){ Cursor cursor = getReadableDatabase().rawQuery("SELECT name FROM contacts", null); String [] names = {""}; for(int i = 0; i <…
Rakeeb Rajbhandari
  • 4,853
  • 6
  • 41
  • 74
5
votes
2 answers

IllegalStateException: database already closed (using ViewPager)

I'm stumped as to what is causing this error, as I have made sure that I am closing my database adapter properly (at least I think I am). Here's what LogCat's saying (the tag for all of them is AndroidRuntime): FATAL EXCEPTION: main …
4
votes
3 answers

Move cursor to row by one of the columns

After querying the data I wanted, I now have a cursor holding all the data, presented to the user in a Listview. When a user clicks an item in order to edit it, I move the cursor to the right position cursor.moveToPosition(pos), from which I can get…
Lior Iluz
  • 25,118
  • 15
  • 63
  • 107
4
votes
2 answers

Turn SQLite columns to rows

I am trying to convert a query which returns a single row with multiple columns to multiple rows with one or multiple columns. As an example my query looks like the following visualized: SELECT _id, value1, value2, value3, value4 FROM table WHERE…
4
votes
4 answers

update contact name & number in android programmatically

I create an Application to Read, Update, Delete Contacts Details. Here is a problem to updating Contact name and number.Could anyone help me please how can I do that. I am using the following code, but it's not working. @Override public View…
Secret
  • 541
  • 1
  • 7
  • 28
4
votes
2 answers

Android: is Cursor.getColumnIndex() invariant over row loop?

It seems like android.database.Cursor.getColumnIndex(String) should be invariant over the row loop. Yet I see loads of code doing stuff like: try (Cursor cursor = database.query(...)) { while (cursor.moveToNext()) { String aString =…
Jess Holle
  • 583
  • 4
  • 13
4
votes
1 answer

Difference between cursor.setNotificationUri() and getContentResolver().notifyChange(uri,null)

I am new to android can any one tell me what is the difference between cursor.setNotificationUri() and getContentResolver().notifyChange(uri,null) while implementing content provider. I have seen that cursor.setNotificationUri() is used in query()…
FaisalAhmed
  • 2,603
  • 3
  • 33
  • 61
4
votes
2 answers

Cursor.moveToNext error

I'm seeing a crash report for this occassionally: Fatal Exception: java.lang.IllegalStateException: Couldn't read row 1127, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it. at…
Anthony
  • 7,121
  • 3
  • 33
  • 66
4
votes
2 answers

Android - SQLiteException: near "=": syntax error (code 1)

I am trying to log id from users table and jobname from jobs table using user id String select = "SELECT jobname FROM " + TABLE_JOBS+ "where userid =" +myid;
Sophie
  • 2,384
  • 10
  • 39
  • 71
4
votes
1 answer

Unable to identify WhatsApp contacts

I'm trying to write an Android program which can identify if a given contact number is associated with WhatsApp or not. I managed to find out if a particular contact name has WhatsApp account or not. How can I find out which contact corresponding to…
4
votes
2 answers

Getting the result of cursor and turning it into a string for TextView

This is my query : Cursor nextdate(String Date) { SQLiteDatabase db = this.getReadableDatabase(); String[] params = new String[]{String.valueOf(Date)}; Cursor cur = db.rawQuery(" SELECT MIN (" + colDateDue + ") FROM " + PAYMENTS + "…
Cytus
  • 261
  • 1
  • 2
  • 10
4
votes
2 answers

Index 0 Requested with a size of 0 Error in SQLITE DB

There is data in the database (2 rows to be precise) with info in each. Here is the code (that matters, not all of it) from the DBADAPTER: // Field Names: public static final String KEY_ROWID = "_id"; public static final String KEY_DEVICE =…
JDSlimz
  • 101
  • 1
  • 8