问题描述
我创建一个微调
,我已经添加了一个 OnItemSelectedListener
给它。不过,我已经注意到,它触发上创建。现在,我想知道是否有办法忽略/丢弃它。
I'm creating a spinner
and I've added an OnItemSelectedListener
to it.However I've noticed that it fires on create.Now I was wondering if there was a way to ignore/discard it.
我知道我可以使用布尔
的价值,但是这是一个有点脏。
I know I could use a boolean
value, but that's a bit "dirty".
推荐答案
您不应试图prevent在调用 OnItemSelectedListener
。
You should not attempt to prevent the call to the OnItemSelectedListener
.
在默认情况下,Android的纱厂选择由适配器返回的第一个项目,因此 OnItemSelectedListener
被调用来触发该项目的一些动作。
By default, Android Spinners select the first item returned by the Adapter, and therefore the OnItemSelectedListener
is called to trigger some action on that item.
我会建议,在您的微调适配器的第一个项目是一个空白的项目,你的 OnItemSelectedListener
可以根据ID忽略空白项。
I would advise that the first item in your Spinner Adapter be a blank item, and your OnItemSelectedListener
can ignore that blank item based on its id.
这篇关于忽略OnItemSelectedListener射击创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!