Mike jess
Mike jess

Reputation: 151

how change color of RadioGroup buttons that uncheck after button event in android

I try to build android app that using to chose single answer from multi-answers in RadioGroup and there just one correct answer whit id and there no id for incorrect RadioButtons

I want to change text color of the correct answer to green and red to others after button click event onClick .

Thanks in advance. Any help is greatly appreciated.

Upvotes: 0

Views: 456

Answers (1)

Tekhita Fanta
Tekhita Fanta

Reputation: 61

If I understand you right.. you just need to change textcolor of your radiobutton?

I don't sure this is the best solution, but you can achive this this way. It's abstract code.. adapt it for your situation:

    RadioGroup group = view.findViewById(R.id.my_radiogroup);
    int count = group.getChildCount();
    for (int i = 0; i < count; i++) {
        RadioButton button = (RadioButton)group.getChildAt(i);
        button.setTextColor(Color.RED);
    }

    RadioButton corectAnswer = (RadioButton) view.findViewById(R.id.answer);
    corectAnswer.setTextColor(Color.GREEN);

Hope this help. Good Luck.

Upvotes: 1

Related Questions