onItemSelectedListener 仅在选择实际更改时触发?

发布于 2024-11-29 16:57:49 字数 197 浏览 1 评论 0原文

我在微调器上使用 setOnItemSelectedListener 。 如果我更改选择,则会触发侦听器,但如果我选择已选择的同一项目,则不会触发侦听器。 即使用户选择已选择的相同项目,我也需要得到通知。 我考虑过使用 setOnItemClickListener,但 Spinner 不支持它。

有什么提示吗?

TIA

I use setOnItemSelectedListener on a spinner.
The listener is triggered if I change the selection but not if I select the same item that is already selected.
I need to be nofified even if the user select the same item that is already selected.
I tought about using setOnItemClickListener but it is not supported by the Spinner.

Any hints ?

TIA

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不羁少年 2024-12-06 16:57:49

如果您仍在寻找这个问题的解决方案,Regis,可能值得一看 我不久前提出的一个相关问题,其中有几个答案,其中提供了关于如何解决此问题的好主意。

If you're still looking for a solution to this question, Regis, it may be worth having a look at a related question I asked a while ago, which has several answers with good ideas on how to work around this issue.

埖埖迣鎅 2024-12-06 16:57:49

您是否尝试过重写onNothingSelected()?在 onNS() 中,您实现执行/获取/“默认”选择的任何项目。我希望你明白我的想法。

spin.setOnItemSelectedListener(new OnItemSelectedListener(){

@Override
    public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
                        // Some operation with other selection
                            }
    @Override
      public void onNothingSelected(AdapterView<?> arg0) {
    //operation with that item that onItemSelected() did not triggered. I mean, let's say you have 3 items on the spinner: A,B,C. Initially what we see its the A item and on this item this method will apply.
    }});

Did you tried to override onNothingSelected()? in onNS() you implement to do/get/whatever item that is selected by "default". I hope you get my idea.

spin.setOnItemSelectedListener(new OnItemSelectedListener(){

@Override
    public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
                        // Some operation with other selection
                            }
    @Override
      public void onNothingSelected(AdapterView<?> arg0) {
    //operation with that item that onItemSelected() did not triggered. I mean, let's say you have 3 items on the spinner: A,B,C. Initially what we see its the A item and on this item this method will apply.
    }});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文