I just used the answer @ spaaarky21
and my full code looks like this and it works great!
Java class
public class ToggleableRadioButton extends RadioButton { public ToggleableRadioButton(Context context) { super(context); } public ToggleableRadioButton(Context context, AttributeSet attrs) { super(context, attrs); } public ToggleableRadioButton(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public ToggleableRadioButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Override public void toggle() { if(isChecked()) { if(getParent() instanceof RadioGroup) { ((RadioGroup)getParent()).clearCheck(); } } else { setChecked(true); } } }
And for the XML layout
<com.smart_dent.adapters.ToggleableRadioButton android:id="@+id/tejido_blando_perfil_convexo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/tejido_blando_convexo_label" />
In this case, you just need to change the package, I can easily find it, it is on top of the Java Class Flie (if you created it from Android Studio)
source share