gpt4 book ai didi

Android Spinner 所选项目

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:29:41 25 4
gpt4 key购买 nike

我正在像这样从数据库中填充一个微调器

    // 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);

当我尝试像这样从微调器的选定项目中获取内容时

// Get the City
Spinner getCity = (Spinner) findViewById(R.id.citySpiner);
String cityName = getCity.getSelectedItem().toString();

我得到以下信息。有没有办法从数据库中获取城市名称或城市 ID。

enter image description here

最佳答案

我认为,当您使用自定义适配器并在适配器中提供三个列表时...

你不能简单地通过调用 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... :)

希望对你有帮助....

关于Android Spinner 所选项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5818850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com