1
SQLite
クエリはCursor
を返します。 Cursor
に余分な行を追加するには、MatrixCursor
(クリックすると実際のデータの最初の項目が自動的に選択されないようにする)を実装します。次に、それらをSimpleCursorAdapter
にマップしたいと思います。私はポスト(とコード)を読んだが、以下のリストにある私のコードにそれをコード化する方法はまだ分かりません。SpinnerのMatrixCursorを実装するにはどうすればよいですか?
Cursor cursor = myDB.query(DATABASE_TABLE_NAME, resultColumns, whereClause,
whereArgs, null, null, null, null);
// Create Spinner View object from layout resource
Spinner spinner = (Spinner) findViewById(R.id.spinner);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_spinner_item, // Use a template
// that displays a
// text view
cursor, // Give the cursor to the adapter
new String[] {"ename"}, // Map the NAME column in the
// people database to...
new int[] {android.R.id.text1});
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
大変ありがとうございます – j2me
'new Long(-2)'の代わりに 'Long.valueOf(-2)'を使用してください。 – bancer