Reputation: 48686
I have a group of radiobuttons in Android inside a RadioGroup and when one radio button gets selected, the currently selected radio button is deselected and the one I clicked on gets selected, which is what should happen.
What I want to know is if its possible to determine the previous radio button that was deselected was? Like this diagram shows:
( ) Option 1
(o) Option 2
( ) Option 3
Option 2 is selected right now. Now I am going to select Option 3:
( ) Option 1
( ) Option 2
(o) Option 3
On my OnClick handler for Option 3, is it possible to know that Option 2 was the previously selected option?
Upvotes: 0
Views: 1369
Reputation: 1726
you should put all your radiobuttons in a RadioGroup: http://developer.android.com/reference/android/widget/RadioGroup.html Use the following method of radioGroup to get the checked radio button id.
getCheckedRadioButtonId();
Do this before you check another button. The check should be done in OnCheckedChangeListener.
Upvotes: 2
Reputation: 30855
you can store the position value in int value like
int position=2 /////// this default select when start
now when you click on any radio button then get the position first that which one last position and after whatever you want to doing set the position value to the current selection
Upvotes: 2