我有一个SQLite
返回Cursor
. 我想Cursor
通过实现 a来添加一些额外的行MatrixCursor
(以尝试在单击时自动选择第一项真实数据)。然后我想将它们映射到SimpleCursorAdapter
. 我一直在阅读帖子(和代码),但我仍然不清楚如何将其编码为下面列出的现有代码。
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());