i have been trying to bind spinner to a database and finally got succeeded. i have connected spinner to database table using cursoradapter. but the problem is the spinner gets populated but the list items in it shows blank text. i know binding is successful because it shows as many rows as there are records in database table. can not figure out what it is. some body please help i am stuck here i am posting the code below
public long createAccount() {
ContentValues initialValues = createContentValues();
Log.i("DB", initialValues.get(KEY_NAME)+":"+
initialValues.get(KEY_MAILBOXTYPE)+":"+
initialValues.get(KEY_OUTPORT)+":"+
initialValues.get(KEY_INPORT)+":"+
initialValues.get(KEY_INSERVER)+":"+
initialValues.get(KEY_OUTSERVER)+":");
return database.insert(DATABASE_TABLE, null, initialValues);
}
/**
* Return a Cursor over the list of all todo in the 开发者_如何学JAVAdatabase
*
* @return Cursor over all notes
*/
public Cursor fetchAccount() {
Log.i("DB", "Cursor opened");
return database.query(DATABASE_TABLE, new String[] { KEY_ROWID,
KEY_NAME,KEY_INSERVER}, null, null, null,
null, null);
}
Code for spinner binding is below:
mAccAdap.createAccount();
Cursor c = mAccAdap.fetchAccount();
startManagingCursor(c);
SimpleCursorAdapter CursorAdapter = new SimpleCursorAdapter(
this,android.R.layout.simple_spinner_item,c,
new String[]{mAccAdap.KEY_INSERVER},new int[]{R.id.tvDBViewRow});
CursorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinEmail=(Spinner)findViewById(R.id.spinAccount);
spinEmail.setAdapter(CursorAdapter);
Try changing this part of your SimpleCursorAdapter
...
new int[]{R.id.tvDBViewRow}
to this...
new int[]{android.R.id.text1}
精彩评论