Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.
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)
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());}}}