If I set a radio button to be selected on the first time, it works fine. But if I unselect it by calling .setChecked(false); then, later even if I try to make it selected by calling setChecked(true) will not unselect the previous one.
private void radiotype() {
count = //changed every time.
LinearLayout llques = (LinearLayout) mview.findViewById(R.id.llrbgRBD);
RadioGroup group = new RadioGroup(context);
group.setOrientation(RadioGroup.VERTICAL);
final RadioButton[] rb = new RadioButton[count];
List<String[]> ans = getAnswerList.getAns();
for (int j = 0; j < count; j++) {
rb[j] = new RadioButton(context);
rb[j].setVisibility(View.VISIBLE);
rb[j].setText("`enter code here`hi");
String a = rb[j].getText().toString();`enter code here`
Log.e("getAnswerList===a", "getAnswerList===>a" + a);
Log.e("getAnswerList", "getAnswerList===>" + ans.get(index)[0]);
if (a.equalsIgnoreCase(ans.get(index)[0])) {
rb[j].setChecked(true);
}
rb[j].setTextColor(Color.BLACK);
rb[j].setButtonDrawable(R.drawable.custom_radio_button);
group.addView(rb[j]);
}
llques.removeAllViews();
llques.addView(group);
group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
// checkedId is the RadioButton selected
//int c = count;
for(int i=0;i<count;i++){
rb[i].setChecked(false);
}
//
Log.v("id",""+checkedId);
for (int i = 0; i < count; i++) {
if (rb[i].getId() == checkedId){
rb[i].setChecked(true);
}
}
}
});