Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android.database.sqlite.SQLiteCursor@435b9ba0

I am getting the text 'android.database.sqlite.SQLiteCursor@435b9ba0' returned from a spinner.getSelectedItem().toString() call. I'm not sure why. The spinner is tied to a SimpleCursorAdapter.

Here is the code

    cCategories = (Cursor) myAdapter.getAllCategories();
    this.startManagingCursor(cCategories);

    SimpleCursorAdapter scaCategories = new SimpleCursorAdapter(this, R.layout.track_category_item,cCategories,new String[] {DBAdapter.KEY_CATEGORIES_NAME},new int[]{R.id.text1});
    scaCategories.setDropDownViewResource(R.layout.track_category_dropdown_item); 
    mCatSpinner = (Spinner) findViewById(R.id.thecategory);
    mCatSpinner.setAdapter(scaCategories);

    if(mCatSpinner.isSelected() != true) {
        mCatSpinner.setSelection(0);
    }

and the xml track_category_item.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/text1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@android:id/text1"
    style="?android:attr/spinnerItemStyle"
    android:ellipsize="marquee"
    android:singleLine="true">
</TextView>

track_category_dropdown_item.xml

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"           
    android:id="@+id/text1"
    style="?android:attr/spinnerDropDownItemStyle"
    android:singleLine="true"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:ellipsize="marquee" />

The spinner xml looks like this

<Spinner
    android:id="@+id/thecategory"
    android:prompt="@string/SELECT_CATEGORY"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_x="15px"
    android:layout_y="133px" >
</Spinner>

and the cursor being returned is

public Cursor getAllCategories() 
{
    return db.query(DATABASE_CATEGORIES_TABLE, new String[] {
            KEY_CATEGORIES_ROWID,
            KEY_CATEGORIES_NAME,
            KEY_CATEGORIES_DEFAULT}, 
            null, 
            null, 
            null, 
            null, 
            null);
}

The spinner appears to work properly. When I try to save this is what is passed as the value of the selected item using spinner.getSelectedItem().toString().

Anyone see anything blatently wrong here. not sure what to do.

thanks patrick

like image 381
bugzy Avatar asked Jan 16 '10 00:01

bugzy


People also ask

How cursor works in SQLite database?

Once a cursor has been returned from a database query, an app needs to iterate over the result set and read the column data from the cursor. Internally, the cursor stores the rows of data returned by the query along with a position that points to the current row of data in the result set.

What is cursor in SQLite Android?

SQLiteCursor. A Cursor implementation that exposes results from a query on a SQLiteDatabase . This interface provides random read-write access to the result set returned by a database query.

What is SQLite database in Android?

SQLite Database is an open-source database provided in Android which is used to store data inside the user's device in the form of a Text file. We can perform so many operations on this data such as adding new data, updating, reading, and deleting this data.

What is SQLite open helper in Android?

SQLiteOpenHelper class The android. database. sqlite. SQLiteOpenHelper class is used for database creation and version management. For performing any database operation, you have to provide the implementation of onCreate() and onUpgrade() methods of SQLiteOpenHelper class.


2 Answers

Your code is working as you wrote it. Spinner is an AdapterView. The adapter you connected it to is a SimpleCursorAdapter. This means that the selected item is a Cursor (positioned at the item in the Cursor's result set corresponding with the user's choice). Cursor has the default implementation of toString(), which returns something like android.database.sqlite.SQLiteCursor@435b9ba0.

Since you didn't tell us what you are trying to do, it is impossible to accurately advise you further. Whatever it is you want to save, however, needs to be pulled out of the Cursor you get from getSelectedItem().

like image 110
CommonsWare Avatar answered Oct 04 '22 03:10

CommonsWare


i can be bothered reading your context, but just wanted to briefly help. i have a column named after DbHelper.KEY_COL, and i am retrieving a DbHelper.KEY_COL value at a specific row. perhaps some of my code would help:

Cursor colCur=(Cursor)spCols.getSelectedItem();
String col=colCur.getString(colCur.getColumnIndex(DbHelper.KEY_COL));
like image 38
easoncxz Avatar answered Oct 04 '22 05:10

easoncxz