Har*_*M V 6 database android cursor spinner
我像这样从数据库中填充一个微调器
// Populating the City Spinner
Cursor cities = db.cityList();
startManagingCursor(cities);
// create an array to specify which fields we want to display
String[] from = new String[] { DBAdapter.KEY_NAME };
// create an array of the display item we want to bind our data to
int[] to = new int[] { android.R.id.text1 };
Spinner cityList = (Spinner) this.findViewById(R.id.citySpiner);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, cities, from, to);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
cityList.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
当我尝试从这个微调器的选定项目中获取内容时
// Get the City
Spinner getCity = (Spinner) findViewById(R.id.citySpiner);
String cityName = getCity.getSelectedItem().toString();
Run Code Online (Sandbox Code Playgroud)
我得到以下内容.有没有办法从数据库中获取城市名称或城市ID.

我想,因为你正在使用一个customadapter并在适配器中给出三个列表...
您只需通过调用getSelectedItem()即可获得所选文本.
用这个:
Spinner mySpinner = (Spinner)findViewbyId(R.id.spinner);
int position = mySpinner.getSelectedItemPosition();
String Text = yourCityList[position].toString(); // dont know which list is holding the city list...
// i didn't use any db in any of my app so cant tell you how can you get list...
// leaving it to you... :)
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你....
只需从微调器获取适配器并从光标获取字符串
Cursor cursor = (Cursor) myAdapter.getItem(position);
String cityName = cursor.getString(cursor.getColumnIndex(DBAdapter.KEY_NAME));
Run Code Online (Sandbox Code Playgroud)