获取spinner上value的问题
源码:list =(Spinner) findViewById(R.id.list);
db = new MySQLiteHelper(this,DB_NAME,null,VERSION).getReadableDatabase();
String col[]={"_id","carname"};
Cursor cs=db.query("clxx", col, null, null, null, null, null);
SimpleCursorAdapter adpater=new SimpleCursorAdapter(this
, android.R.layout.simple_dropdown_item_1line, cs,
new String[]{"carname"},
new int[]{android.R.id.text1});
list.setAdapter(adpater);
我的spinner上的选项均从数据库表“clxx”的“carname”里读取
然后后面程序需要要获得spinner上选中的内容
但是String s2=list.getSelectedItem().toString();的结果是如图所示:
不知道怎么办了,那个“android.database.sqlite.sqlitecursor@...”的部分即是我想获得的内容...怎么把“android.database.sqlite.sqlitecursor@...”的真正内容String出来啊?
--------------------编程问答-------------------- String col[]={"_id","carname"};
不查询_id列,只查询carname试试
String col[]={"carname"};
--------------------编程问答-------------------- 不行,会报错...SimpleCursorAdapter必须用到_id --------------------编程问答--------------------
解决了!!!
Cursor cursor=(Cursor)list.getSelectedItem();
String s=cursor.getString(1);
s即是逍遥获得的value --------------------编程问答-------------------- 结果遍历啊 --------------------编程问答-------------------- 介个。。。 --------------------编程问答-------------------- SimpleCursorAdapter真是好东西,太省事儿了
补充:移动开发 , Android