Adding data to a database cursor

Maybe I'm going about this the wrong way, but if so, please correct me. Here is the situation: I have a query which returns URI strings for ringtones stored in a database.

I am trying to add a "column" to this cursor with the ringer "Title" (since this can change outside my program).

I can successfully use RingtoneManager to get the title, but I cannot figure out how to add this "column" to the cursor data for later use.

Here is what I have so far:

if (cursor != null) {  
    cursor.moveToFirst();  
    do {  
        String ringerTitle =   getRingerTitle(cursor.getString(cursor.getColumnIndex(PoolDbAdapter.KEY_RINGER)));  

        // How can I add ringerTitle to a new column here?

    } while (cursor.moveToNext());   
}


Asked by: John210 | Posted: 25-01-2022






Answer 1

You cannot modify an existing Cursor this way. You need to create the Cursor with the data you seek at the outset.

More likely, though, you do not need to modify the Cursor, but rather whatever is using the Cursor has to be smarter. For example, if your issue is that you cannot use a computed column in SimpleCursorAdapter, you need to switch to CursorAdapter and override bindView() to have the smarts you want.

Answered by: Freddie564 | Posted: 26-02-2022



Answer 2

I haven't tried it yet (I will update here when I do) but, maybe the following steps would work:

For arguments sake let's call the original cursor baseCursor

  1. Use a MatrixCursor to create the new column that you want to add (let's call it newColumnCursor)
  2. Then create a Cursor [] with baseCursor and newColumnCursor as elements.
  3. Pass that array to MergeCursor.

Answered by: Roland845 | Posted: 26-02-2022



Answer 3

please take a look at this thread:

Writing to cursor:

Answered by: Roland203 | Posted: 26-02-2022



Similar questions

Update Database Android

Can anyone tell me how to update the database in android. I created an app with an embedded database. I changed the version of the database in the manifest and created the on update method. I wanted to test it to see if the database was updating properly but when I use the adb command only the -r will allow me to do a reinstall but it keeps the database. Is there a way to run the adb command that will allow me to update th...


android - Backup and restore SQLite database to sdcard

How can I backup my database to the sdcard automatically in my app? And afterward, how do I restore it?


Select first SMS on Android database inbox

I am desperate to find the solution so I ask for help! I am a new french programmer. My objective is to create a widget able to show SMS. My problem is that I don't know how create a cursor which select the first SMS in content://sms/inbox Excuse my bad English, I hope you will able to understand my wich. Thank you for your answer. this is my code: package sfeir.monwidget; import android.R.string; import an...


android - where is database file in the device

iam trying to locate the database files on my nexus device.. is there anyway of doing it without rooting the device? thanks ray.


how to get macid and mobile number only in android mobile device not in database

how to get macid and mobile number only in android mobile device not in database


android import export database

there. I am trying to implement a feature into my app to copy the current database unto the sdcard. Are there any tutorials or code snippets to achieve this. I've already looked at this site, http://mgmblog.com/2009/02/06/export-an-android-sqlite-db-to-an-xml-file-on-the-sd-card/ ... but I wont be able t...


Android database backups

I'm looking for ways to back up the database of my app on an Android phone. I know that SQLite databases are just files, so I'd expect to be able to just copy the file to SD-card if one is available. However, I'm unsure as to how I'd prepare my database/activity for backup/restore. When starting, my main activity reads the entries from one table in the database and displays them in a ListView. ...


android - How to use my own sqlite database?

I put my database field in "assets" folder. And use the code from this blog to copy the database to "/data/data/my_packname/databases/", (This copy code i run it in the onCreate() method when i run this app) then use select * from ... to get data. But it gives me the exception: no such table. Some...


android - Use DDMS to push the sqlite database file faild

i did not find my package name folder in the data/data. There just are many folder named com And then i try to push my sqlite database to data/data/com, But faild. Why? Pls help me . Can give me a smaple? How to use already exist sqlite database. I have learned from a blog :


android - Using my own SQLite Database

I have a sqlite database, and i put this file in "assets" folder. The code like below, Pls help and tell what's wrong in this code, How to use my own sqlite database. public class DataBaseHelper extends SQLiteOpenHelper { private static String DB_PATH = "/data/data/com.SGMalls/databases/"; private static String DB_NAME = "mallMapv2.sqlite"; private SQLiteDatabase myDataB...


Update Database Android

Can anyone tell me how to update the database in android. I created an app with an embedded database. I changed the version of the database in the manifest and created the on update method. I wanted to test it to see if the database was updating properly but when I use the adb command only the -r will allow me to do a reinstall but it keeps the database. Is there a way to run the adb command that will allow me to update th...


android - static database class to use with any activity

I am new to Android, and I haven't developed any app regarding databases on Android yet. So I have a few basic questions. I am after a good database class sample, that will let me to run the CRUD operations. I would like to use it as a static class like: clsDB->Select("select * from clients"); or objClient->Delete(clientid); I am wondering if some...


android - Backup and restore SQLite database to sdcard

How can I backup my database to the sdcard automatically in my app? And afterward, how do I restore it?


Loading flat files into Android database table

In Android when you upgrade a database all data is lost. I'm going through a phase of development right now that is forcing many database upgrades. I don't want to lose all my data (and have to manually re-enter it) each time I upgrade my database. I would like to store my data in flat files and load those flat files into their respective tables each time a database upgrade occurs. Wha...


Select first SMS on Android database inbox

I am desperate to find the solution so I ask for help! I am a new french programmer. My objective is to create a widget able to show SMS. My problem is that I don't know how create a cursor which select the first SMS in content://sms/inbox Excuse my bad English, I hope you will able to understand my wich. Thank you for your answer. this is my code: package sfeir.monwidget; import android.R.string; import an...


android - where is database file in the device

iam trying to locate the database files on my nexus device.. is there anyway of doing it without rooting the device? thanks ray.


how to get macid and mobile number only in android mobile device not in database

how to get macid and mobile number only in android mobile device not in database


Correct path to sqlite database used by JAR imported into my Android app?

My Android app is using a database through an API packaged in an external JAR. Since the JAR is opening/updating/closing the SQLite database file, do I need to make sure it uses its own package name instead of my own? Im getting errors where it fails to open the database file and Im guessing its because the package name Im telling it to use is incorrect: should it be using the package name in the JAR file? Code tha...


android import export database

there. I am trying to implement a feature into my app to copy the current database unto the sdcard. Are there any tutorials or code snippets to achieve this. I've already looked at this site, http://mgmblog.com/2009/02/06/export-an-android-sqlite-db-to-an-xml-file-on-the-sd-card/ ... but I wont be able t...


Android database backups

I'm looking for ways to back up the database of my app on an Android phone. I know that SQLite databases are just files, so I'd expect to be able to just copy the file to SD-card if one is available. However, I'm unsure as to how I'd prepare my database/activity for backup/restore. When starting, my main activity reads the entries from one table in the database and displays them in a ListView. ...






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top