我正在從spinner.getSelectedItem()。toString()調用返回文本'[email protected]'。我不知道爲什麼。微調器綁定到SimpleCursorAdapter。[email protected]
下面是代碼
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()作爲選定項目的值傳遞的內容。
任何人都可以在這裏看到任何錯誤的東西。不知道該怎麼辦。
感謝 帕特里克
這對於ArrayAdapter來說是正確的。然後傳遞的值是類別的文本(Business或Personal)。我使用SimpleCursorAdapter的事實是否改變了值的傳遞方式? – bugzy 2010-01-16 01:40:18