Android 旋转提示不起作用
我有在我的应用程序中使用的 Spinners。他们工作得很好,只有一个例外。我已经为每一项设置了提示,但它们没有显示。我在 onCreate
期间将 ArrayAdapters
设置为 Spinners,我的猜测是 setAdapter
方法会自动将选择设置为位置 0。一种设置提示并使其按预期工作的方法?
这是一段代码:
来自布局文件:
<Spinner android:id="@+id/selPunter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/select_quarterback_prompt"
android:layout_marginLeft="20sp"
android:layout_marginRight="20sp" />
来自活动:
offenseList = new ArrayAdapter<PlayerVO>(this,
R.layout.select_item_closed,
gdm.getPlayersByTeamId(offenseId));
offenseList.setDropDownViewResource(R.layout.select_item);
selKicker.setAdapter(offenseList);
I have Spinners that I am using in my application. They are working fine with one exception. I have set prompts for each one, but they are not showing. I am setting ArrayAdapters
to the Spinners during onCreate
, and my guess is that the setAdapter
method is automatically setting the selection to position 0. Is there a way to set the prompt and have it work as expected?
Here is a code piece:
From the layout file:
<Spinner android:id="@+id/selPunter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/select_quarterback_prompt"
android:layout_marginLeft="20sp"
android:layout_marginRight="20sp" />
From activity:
offenseList = new ArrayAdapter<PlayerVO>(this,
R.layout.select_item_closed,
gdm.getPlayersByTeamId(offenseId));
offenseList.setDropDownViewResource(R.layout.select_item);
selKicker.setAdapter(offenseList);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
即使您将 OnItemSelectedListener 放在活动的 onStart() 方法中,这种情况似乎也会发生。
我针对此问题所做的解决方法是在资源数组的位置 0 中放置一条默认消息(“选择行程类型”)。因此,当调用 OnItemSelectedListener 时,如果选择了位置 0,则不执行任何操作。这是我的代码:
This seems to happen even if you put the OnItemSelectedListener in the onStart() method of the activity.
The work around I did for this issue was I put a default message in position 0 of my resource array ("Select Trip Type"). So when the OnItemSelectedListener is called, if position 0 is selected, then do nothing. Here is my code: