RadioGroup rg = new RadioGroup(context);
for (int i = 0; i < formElement.getRadioOptions().size(); i++) {
RadioButton radiobutton1 = new RadioButton(context);
radiobutton1.setText(formElement.getRadioOptions().get(i).getValue());
radiobutton1.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources().getDimension(R.dimen.meetingNoteCL));
radiobutton1.setHighlightColor(context.getResources().getColor(R.color.text_color));
rg.addView(radiobutton1);
}
textInputLayout.setTypeface(FontUtils.getFontTypeRegular(context));
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// checkedId is the RadioButton selected
int radioButtonID = group.getCheckedRadioButtonId();
View radioButton = group.findViewById(radioButtonID);
int idx = group.indexOfChild(radioButton);
formElement.setKey(formElement.getRadioOptions().get(idx).getKey());
formElement.setValue(formElement.getRadioOptions().get(idx).getValue());
}
});
above code for radio button ., but after choose I need to change the particular radio button color alone to blue. can u help on this
The onCheckedChanged callback has a checkedId which you can use to get that particular button
You just need to assign your buttons unique ids before adding them to the group. Here is your your code modified to achieve that.