3

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());   
}
2
  • Where does your cursor come from? Can you show the query? Commented Jan 10, 2010 at 20:04
  • The cursor comes from a DB query and returns URIs related to ringtones, eg "content://media/audio/3" Commented Jan 10, 2010 at 20:24

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Unfortunately this suffers the same problem my previous extension of SimpleCursorAdapter had. I cannot control the fact that bindView (or my previous ways getView) is called multiple times per row, which results in alot of lost time querying the RingtoneManager several times for the same data. I want to query only ONCE.. is there another way I am missing to map the values?
Cache the value in the row via setTag(). You can use the same techniques as I advise for caching findViewById() lookups, in this free excerpt from one of my books: commonsware.com/Android/excerpt.pdf
i cannot seem to find out how setTag and getTag can be realted to a specific row (only layouts, ids, etc).. could you provide an example of this?
Yeah, in reading your follow-up question, I realized that my answer was incorrect.
1

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.

Comments

0

please take a look at this thread:

Writing to cursor:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.