如何将Spinner默认值设置为null? [英] How to set Spinner default value to null?
问题描述
我正在尝试使Spinner加载而没有选定的值.用户选择一个值后,它将带他们到另一个页面.
I'm trying to get a Spinner to load up with no selected value. Once the user selects a value it then takes them to another page.
这被证明是一个问题,因为当前页面只是在用户获得选择权之前立即加载.
This is proving to be a problem because at present, the page just loads straight away before the user gets a choice to choose.
我的Spinner类的设置方法与Google的设置方法相同: http://developer.android.com/resources/tutorials/views/hello-spinner.html
My spinner class is set up the same way as Google's: http://developer.android.com/resources/tutorials/views/hello-spinner.html
因此,基本上,是否有可能在不选择任何内容的情况下加载微调器,因为当前它会加载我的字符串数组中的第一项.
So basically, is it possible have a spinner that loads with nothing selected because at present, it loads the first item in my string array.
推荐答案
是否有可能在不选择任何内容的情况下加载微调器
is it possible have a spinner that loads with nothing selected
仅当没有数据时.如果SpinnerAdapter
中有1个以上的项目,则Spinner
始终会有一个选择.
Only if there is no data. If you have 1+ items in the SpinnerAdapter
, the Spinner
will always have a selection.
Spinners
并非设计为命令窗口小部件.用户不会期望在Spinner
中进行选择来启动活动.请考虑使用其他内容,例如ListView
或GridView
,而不是Spinner
.
Spinners
are not designed to be command widgets. Users will not expect a selection in a Spinner
to start an activity. Please consider using something else, like a ListView
or GridView
, instead of a Spinner
.
编辑
顺便说一句,我忘了提到-您总是可以在适配器中添加一个表示无选择"的额外条目,并将其作为Spinner
中的初始选定项.
BTW, I forgot to mention -- you can always put an extra entry in your adapter that represents "no selection", and make it the initial selected item in the Spinner
.
这篇关于如何将Spinner默认值设置为null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!