我已经填充了我的微调器:
DatabaseConnector dbConnector = new DatabaseConnector(this);
dbConnector.open();
Cursor c = dbConnector.raw("SELECT _id, nombrecasa FROM casa");
startManagingCursor(c);
String[] from = new String[]{"nombrecasa"};
int[] to = new int[]{android.R.id.text1};
SimpleCursorAdapter adapter =
new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c, from, to );
adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
casaSpinner = (Spinner) findViewById( R.id.casaspinner);
casaSpinner.setAdapter(adapter);
dbConnector.close();
}
当我尝试将值设为:
String idcasa = casaSpinner.getSelectedItem().toString();
它只会返回:
android.database.sqlite.SQLiteCursor@40539880
答案 0 :(得分:1)
您的微调器已将SimpleCursorAdapter
作为适配器,其数据集为Cursor
。当您在微调器上选择一个项目时,您只将光标移动到特定行,当您调用getSelectedItem()
时,您仍然在请求数据集对象 - 它仍然是一个游标对象。做你想做的事你可以简单地打电话:
c.getString(1);
一旦您做出选择。对于我所说的更为基本的说明。
((Cursor) casaSpinner.getSelectedItem()).getString(1);