I have spinners in my fragment. Selecting each option of my spinners gives me different scores fetching from database. Now, I don't want to fetch the data from database if I select the same option from spinner consecutively. In my current code it is fetching the data on each selection. Is there any way that I can maintain the previous selection of spinners, so that I can give a check to database hit. Thanks.
Asked
Active
Viewed 44 times
-1
-
Can u post what you have tried till now ? – Raj Jul 22 '18 at 06:08
-
Added my answer for the above problem. – Paramita Dec 10 '18 at 21:52
-
This is not a way to ask question in stackoverflow – Ajay Pandya Jun 14 '19 at 09:32
-
Possible duplicate of [Spinner : onItemSelected not called when selected item remains the same](https://stackoverflow.com/questions/10854329/spinner-onitemselected-not-called-when-selected-item-remains-the-same) – Ajay Pandya Jun 14 '19 at 09:33
1 Answers
0
I tried to solve the above problem and was able to find a good solution. I created a custom spinner taking a reference from this answer https://stackoverflow.com/a/11227847/2734855
The overridden method setSelection(int position)
of Spinner class actually gives the event hit back to the OnItemSelectedListener
which helps to track the previous spinner selection.

cybernetic.nomad
- 6,100
- 3
- 18
- 31

Paramita
- 83
- 2
- 11