我的主视图中有两个Spinners。我在这些Spinners中有一个项目列表,我确实使用adapter.getItem(position)
,因为我需要获取值(比如value1
和value2
)我想等待用户选择一个旋转器的两个项目,然后当在任何给定时间发生时,我想执行一些代码。实现这一目标的最有效方法是什么?如果onItemSelected
或value1
为空,我应该检查value2
吗?有什么建议吗?
答案 0 :(得分:1)
检查空值对我来说听起来不错。
//inside onItemSelected()
if (spinner1value != null && spinner2value != null) {
DoYourStuff();
}
答案 1 :(得分:0)
2在伪代码中我会做这样的事情:
spinner1Selected = false;
spinner2Selected = false;
Spinner1ItemSelected {
spinner1Selected = true;
if(spinner1Selected == true && spinner2Selected == true) doMyStuff();
}
Spinner2ItemSelected {
spinner1Selected = true;
if(spinner1Selected == true && spinner2Selected == true) doMyStuff();
}
doMyStuff(){
doing my stuff...
spinner1Selected = false;
spinner2Selected = false;
}