How to add extra elements into Cursor or SimpleCursorAdapter?

by Developer » Sun, 01 Feb 2009 08:08:34 GMT

Sponsored Links
 Suppose I get a cursor that contains all rows from my database, and I
want to show them on a spinner, the following code will work. But I
want to show two extra items as the spinner elements, how can I add
those two elements?

For example, if the following code can show 4 spinner elements
"Orange" "Apple" "Cabbage" "Green Onion", how can I add an element in
the spinner saying "All fruit" "All Vegetable"?


class ShowElements extends Activity {
    private void populateSpinner() {
        Cursor cursor = mDbHelper.fetchAllExistingElements();  // get
all items
        String[] from = new String[]{ ShowElements.KEY_NAME };
        int[] to = new int[]{};
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(
                        this, android.R.layout.simple_spinner_item, cursor, 

How to add extra elements into Cursor or SimpleCursorAdapter?

by Mark Murphy » Sun, 01 Feb 2009 08:15:04 GMT


Here are some ideas...

Option #1: Put the extra two in the database.

Option #2: Don't pass the Cursor into SimpleCursorAdapter, but rather
iterate over the Cursor, put the results into an ArrayList or something,
and use that with an ArrayAdapter.

Option #3: Create a CursorWrapper that injects your two extra values
into the results.

Mark Murphy (a Commons Guy) 
_The Busy Coder's Guide to Android Development_ Version 2.0 Published!


Sponsored Links

Other Threads

1. Helping for UEvent for Battery Service

Dear All

I've implemented power_supply in my charger driver, and it can update
charging information for the power_supply structure such as /sys/class/
power_supply/battery/status ....

However, in Android Java layer of mUEventObserver.startObserving
("SUBSYSTEM=power_supply") cannot receive the notification when the
status or capacity is changed.

What else did I miss??? Can anyone give me some clues?


2. About the NeighboringCellInfo information

Hello everyone,
     I'd like to ask some questions about the "NeighboringCellInfo"
get from the

1. Is the current connected BS information included in the

2. I'm now trying to get the current Cell ID and current RSSI of the
connected BS.
   I can get the current CellID from the
   However, I still can't get the RSSI of that BS.
   Is there any way to get the current BS's RSSI?

Thanks a lot^^


3. Calling all Sydney/Australia Android Developers

4. is there any browser that could be used on Android?

5. Strange Proxy setting and INTERNET problem Emulator

6. What is the difference between findFocus() and focusSearch()

7. What is the difference between findFocus() and focusSearch()