what am i doing wrong
you did not read the documentation ...
There are two row arrays with columns: first in use in the query, the second in the Adapter constructor (you used only one array for both)
first tells sqlite which columns should be moved to Cursor, the second tells Adapter which ones should be shown / displayed in Views on the same line ...
Next, CursorAdapter requires Cursor with a column named _id
So now it’s pretty obvious that we have to do this:
String[] queryCols=new String[]{"_id", "sampletext"}; String[] adapterCols=new String[]{"sampletext"}; int[] adapterRowViews=new int[]{android.R.id.text1}; mycursor=sdb.query(true,"mytable", queryCols,null,null,null,null,null,null); sca=new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, mycursor, adapterCols, adapterRowViews,0); sca.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spn.setAdapter(sca);
source share