Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically Change the Text of RadioButton

I am creating a quiz application in android.For each question I have set up 4 radio buttons for the user to click. How do i change the text of the radiobutton dynamically for each question? The text for these radio button are stored in a raw text file.

like image 508
working Avatar asked Dec 04 '22 16:12

working


1 Answers

Here you go.

I have set up 4 radio buttons for the user to click.

You must have defined them in radioGroup,right?

Then you can iterate in RadioGroup to set names to RadioButton or you can get RadioButton by index and set name to it.

RadioGroup radioGroup = (RadioGroup)findViewById(R.id.group);

    for (int i = 0; i < radioGroup .getChildCount(); i++) {
            ((RadioButton) radioGroup.getChildAt(i)).setText(String.valueOf(i));
        }
like image 56
Vipul Avatar answered Dec 21 '22 14:12

Vipul