I select the value from spinner and when I select the same value again then no action is performed on the click.
2
- 2keep track of the previously selected value... and check whether the current select selected value is previous onePragnani Kinnera– Pragnani Kinnera2013-04-15 10:05:02 +00:00Commented Apr 15, 2013 at 10:05
- check present select valu and previous one both are same or not.RajaReddy PolamReddy– RajaReddy PolamReddy2013-04-15 10:05:19 +00:00Commented Apr 15, 2013 at 10:05
Add a comment |
1 Answer
Use this custom Spinner class...
/** Spinner extension that calls onItemSelected even when the selection is the same as its previous value */ public class NDSpinner extends Spinner { public NDSpinner(Context context) { super(context); } public NDSpinner(Context context, AttributeSet attrs) { super(context, attrs); } public NDSpinner(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public void 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()); } } @Override public void setSelection(int position) { boolean sameSelected = position == getSelectedItemPosition(); super.setSelection(position); 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()); } } }