1
我有一個SQLite
查詢,返回Cursor
。我想通過實施一個MatrixCursor
(爲了保持點擊時自動選擇第一項實際數據)而向Cursor
添加一些額外的行。然後我想將它們映射到SimpleCursorAdapter
。我一直在閱讀帖子(和代碼),但仍然對我如何將其編碼到我現有的代碼下面。如何爲微調器實現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 2012-05-16 06:45:01
使用'Long.valueOf(-2)'而不是'new Long(-2)'。 – bancer 2012-11-02 13:49:17