カテゴリを表示するためのスピナーウィジェットを持つアクティビティがあります。最初は、次のコードのように、ArrayAdapterを使用してスピナーにデータを入力していました
private static final String[] arrayCategories = {
"Business",
"Personal"
};
mCatSpinner = (Spinner) findViewById(R.id.thecategory);
ArrayAdapter<String> catAdapter = new ArrayAdapter<String>(this, R.layout.track_category_item, arrayCategories);
catAdapter.setDropDownViewResource(R.layout.track_category_dropdown_item);
mCatSpinner.setAdapter(catAdapter);
これは正常に機能し、選択が行われない場合、スピナーはデフォルトで最初の配列項目を表示します。アイテムが実際に選択されたときに、選択されたアイテムが表示されます
しかし、ここでSimpleCursorAdapterを使用して、データベースからリストの内容をプルしたいと思います。だから私はそれをに変更しました
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);
これによりドロップダウンが表示されますが、スピナーの最初の項目は表示されません。選択しても、選択したアイテムは表示されません。
を使ってSlectionを最初のアイテムに設定してみました
if(mCatSpinner.isSelected() != true) {
mCatSpinner.setSelection(0);
}
しかし、それは機能しませんでした
なにが問題ですか?