I faced issues with the accepted answer.
Sometimes it makes currently checked radio button unchecked leaving non of the radio buttons selected. This was happening when selecting a radio button in different radio group after selecting a radio button from one group.
Here is the solution, instead of saving last checked RadioButton, save last checked RadioGroup and clear last check if last checked RadioGroup is not the current one and it has a selected RadioButton as shown below.
For more information read http://www.zoftino.com/android-recyclerview-radiogroup
priceGroup = (RadioGroup) view.findViewById(R.id.price_grp);
priceGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
if (lastCheckedRadioGroup != null
&& lastCheckedRadioGroup.getCheckedRadioButtonId()
!= radioGroup.getCheckedRadioButtonId()
&& lastCheckedRadioGroup.getCheckedRadioButtonId() != -1) {
lastCheckedRadioGroup.clearCheck();
Toast.makeText(PackageRecyclerViewAdapter.this.context,
"Radio button clicked " + radioGroup.getCheckedRadioButtonId(),
Toast.LENGTH_SHORT).show();
}
lastCheckedRadioGroup = radioGroup;
}
});