6

我收到从 spinner.getSelectedItem().toString() 调用返回的文本“android.database.sqlite.SQLiteCursor@435b9ba0”。我不确定为什么。微调器绑定到 SimpleCursorAdapter。

这是代码

    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);
    }

和 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" />

微调器 xml 看起来像这样

<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>

并且返回的光标是

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);
}

微调器似乎工作正常。当我尝试保存时,这是使用 spinner.getSelectedItem().toString() 作为所选项目的值传递的。

任何人都在这里看到明显的错误。不知道该怎么办。

谢谢帕特里克

4

2 回答 2

7

您的代码在您编写时工作。Spinner是一个AdapterView。您连接到的适配器是SimpleCursorAdapter. 这意味着选中的项目是一个Cursor(定位在光标结果集中与用户选择对应的项目)。Cursor具有 的默认实现toString(),它返回类似android.database.sqlite.SQLiteCursor@435b9ba0.

由于您没有告诉我们您要做什么,因此无法进一步准确地为您提供建议。但是,无论您想保存什么,都需要从Cursor您从中获得的内容中提取出来getSelectedItem()

于 2010-01-16T01:47:30.313 回答
2

我可能会打扰阅读您的上下文,但只是想简要提供帮助。我有一个以 命名的列DbHelper.KEY_COL,我正在检索DbHelper.KEY_COL特定行的值。也许我的一些代码会有所帮助:

Cursor colCur=(Cursor)spCols.getSelectedItem();
String col=colCur.getString(colCur.getColumnIndex(DbHelper.KEY_COL));
于 2012-09-30T09:20:01.977 回答