Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

Android spinner item selection?

In Android Spinner, if we select the same item again from the spinner, no event will be triggered even we have the item selection listener. How can we show an alert dialog when selecting the first item in a spinner(first time it works)

user-image
Question ajoutée par Sujay PS , Software Engineer , D+H Solutions India Pvt Ltd
Date de publication: 2015/07/27
Miriana Itani
par Miriana Itani , Senior Android Developer , Saudi Research and Publishing Company

A normal spinner does not fire if you click on the same item twice even if you have the listener. Therefore what you can do is create a custom spinner: Something like this : 

 

publicclassNDSpinnerextendsSpinner{publicNDSpinner(Context context){super(context);}publicNDSpinner(Context context,AttributeSet attrs){super(context, attrs);}publicNDSpinner(Context context,AttributeSet attrs,int defStyle){super(context, attrs, defStyle);}@Overridepublicvoid setSelection(int position,boolean animate){boolean sameSelected = position == getSelectedItemPosition();super.setSelection(position, animate);if(sameSelected){// Spinner does not call the OnItemSelectedListener if the same item is selected, so do it manually now getOnItemSelectedListener().onItemSelected(this, getSelectedView(), position, getSelectedItemId());}}}

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?