onItemSelectedListener only triggered if selection actually change?

风流意气都作罢 提交于 2020-01-03 07:29:09

问题


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


回答1:


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.




回答2:


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.
    }});


来源:https://stackoverflow.com/questions/7043183/onitemselectedlistener-only-triggered-if-selection-actually-change

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!