Sahana Kamath
Sahana Kamath

Reputation: 201

Unchecking radio buttons in a Radio Group without the ripple animation

I have a quiz app which displays the question in a textview and the 4 answers in a radio group with 4 radio buttons. To move to the next question, the user has to click a Next button.

When the user selects a particular radio button and clicks on Next button I repopulate my UI with the next question and its answers. Before displaying the next question I clear the radio button selection by using RadioGroup clearCheck().

However the user can see this selection change in the UI.

I have tried setting transparent color to the radio button background but that doesn't solve the issue.

How do I solve this?

Upvotes: 5

Views: 2311

Answers (2)

kezc
kezc

Reputation: 61

You can end the animation by calling radioGroup.jumpDrawablesToCurrentState() after the clearCheck().

Upvotes: 6

Damnum
Damnum

Reputation: 1859

Try adding your own radiobutton drawable like so:

quiz_radiobutton.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_checked="false" android:drawable="@drawable/checkbox_outline" />
        <item android:state_checked="true" android:drawable="@drawable/checkbox_outline_checked" />
</selector>

Then, change your the drawable in your buttons:

<android.support.v7.widget.AppCompatRadioButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:button="@drawable/quiz_radiobutton"
/>

This will deactivate the ripple animations.

Upvotes: 1

Related Questions