Home » Android » android – onItemSelectedListener only triggered if selection actually change?

android – onItemSelectedListener only triggered if selection actually change?

Posted by: admin June 15, 2020 Leave a comment

Questions:

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

How to&Answers:

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.

Answer:

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