Je reçois le texte '[email protected]' renvoyé par un appel à spinner.getSelectedItem(). ToString(). Je ne suis pas sûr pourquoi. Le spinner est lié à un SimpleCursorAdapter.[email protected]
Voici le 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);
}
et 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" />
Le xml ressemble spinner cette
<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>
et le curseur retourné est
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);
}
La fileuse semble fonctionner correctement. Lorsque j'essaie de sauvegarder c'est ce qui est passé comme la valeur de l'élément sélectionné en utilisant spinner.getSelectedItem(). ToString().
Tout le monde voit quelque chose de flagrant mal ici. Je ne sais pas quoi faire.
merci patrick
Cela fonctionnait correctement avec un ArrayAdapter. La valeur transmise était alors le texte de la catégorie (Business ou Personal). Le fait que j'utilise un SimpleCursorAdapter change-t-il la façon dont la valeur est passée? – bugzy