如何将 Spinner 默认值设置为 null? [英] How to set Spinner default value to null?

查看:53
本文介绍了如何将 Spinner 默认值设置为 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.

我的微调器类的设置方式与 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 中的选择来启动活动.请考虑使用其他东西,例如 ListViewGridView,而不是 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆