简体   繁体   English

默认情况下如何在微调框中选择第二个选项?

[英]How to have the 2nd option in a Spinner selected by default?

because of my assignment to recreate an application as much as possible, I cannot change the spinner item order (unless what I'm about to ask is impossible in Android). 由于我要尽可能多地重新创建应用程序,因此我无法更改微调项的顺序(除非我要问的是在Android中是不可能的)。

I populate the spinner using values from a String[]. 我使用String []中的值填充微调器。 When the iOS version is run, the top choice is not selected by default, but the second item is. 运行iOS版本时,默认情况下未选择顶部选项,但第二项是。 I want to keep the same order, so I wanted to know if it would be possible to have the spinner display the second option upon the opening of the activity it resides in. 我想保持相同的顺序,所以我想知道是否有可能让微调框在其所在的活动打开时显示第二个选项。

Thank you very much for the help! 非常感谢你的帮助!

if (mySpinner.getCount() > 1) // if there are at least two items
mySpinner.setSelection(1); // select the second item

You can use this after you set the adapter. 设置适配器后即可使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM