Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Spinner item on click does't work if it is already selected

I've a Spinner with onItemSelected interation that works, but how the Api specification says:

This callback is invoked only when the newly selected position is different from the 
previously selected position or if there was no selected item.

I need to remove this limitation and i want that the callback is invoked also if the user select the same element. How to do that?
Anyone did the same thing?

Any idea about this would be appreciable..

like image 983
Hulk Avatar asked Jun 25 '12 04:06

Hulk


People also ask

How can I get an event in android spinner when the current selected item is selected again?

Find the oldselected position in spinner and make it accesible and set it to -1 means internally its changing the selected position but user can't see. So when user selects same position as previously selected position in the spinner, it will get select without fail.

How can I tell if spinner is clicked or not in android?

Let the Spinner's first value be something like "-please select-". when the user clicks on the next button perform validation and check whether the value of the selectedItem in the spinner is "-please select-" and if yes, then display a toast and ask the the user to select something from the spinner.

Which function is used to get the selected item from the spinner?

getItemAtPosition(i).


1 Answers

i want that the callback is invoked also if the user select the same element. How to do that?

Setting the OnItemClickListener for a Spinner will throw an exception and using ItemSelectedListener you will not be notified if the user click on the selected/same element.

I suppose the only way to overcome this limitation is to use a CustomAdapter for the Spinner items and implement the setOnClickListener for each view in the adapter.

like image 129
Arun George Avatar answered Sep 18 '22 08:09

Arun George