Android - 微调器中的默认选项
如何在微调器中设置默认选项?
我用不同的查询填充了 3 个微调器,也许我只想使用其中 2 个微调器,而不是 3 个。因此始终是微调器中设置的值。我怎样才能避免一个值?因为也许如果填充一个数组,我可以在位置 0 设置默认选项,但我用查询填充旋转器。
我知道微调器是有一个值的,所以也许我可以为它们设置一个默认值,这样在 onitemclicklistener 中我可以避免使用该微调器与 if (valuespinnerselected = "Default" ) 不要做任何事情
How can i set a default option in a spinner?
I filled 3 spinners with differents querys, and maybe i just want to use 2 of that spinners, not the 3. So always is a value set in the spinner. How can i avoid a value? Cause maybe if a fill an array i can set a default option in position 0, but im filling spinners with querys.
I know spinners are made to have a value, so maybe i could put them a default value so in the onitemclicklistener i can avoid using that spinner with an if (valuespinnerselected = "Default" ) dont to anything
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以为
Spinner
的每个索引配置标签和值。认为值
-1
是您要忽略的默认值。这样,我认为这段代码可以帮助您:其中 SpinnerItem 是类:
之后,您可以获取所选项目并查看他的值:
希望这有帮助!
You can configure a label and a value for each index of the
Spinner
.Think that the value
-1
is the default value that you want to ignore. That way, i think that this piece of code can help you:Where SpinnerItem is the class:
After that, you can get the selected item and see his value:
Hope this helped!
我认为最简单的方法是像您提到的那样放置一个默认项目。可能是“请选择”。
I think easiest would be to put a default item like you mentioned. It could be "Please select".