I can't get the below dynamically generated RadioButtons to uncheck when I click on other RadioButton in the same RadioGroup.
I have even resorted to writing my own handler that clears the RadioGroup (below), and tried another that make all RadioButtons .setChecked(false) but this still does not clear the RadioButton that I setChecked in PopulateAccessPoints.
Any ideas?
RelativeLayout rlaAccessPoints;
RadioGroup rg;
public void onRadioButtonClicked(View view) {
// Is the button now checked?
RadioButton rd = (RadioButton)view;
rg.clearCheck();
rd.setChecked(true);
}
private void PopulateAccessPoints(List<clsAccessPoint> accessPoints){
rg = new RadioGroup(this);
for (clsAccessPoint acp : accessPoints) {
RadioButton rd = new RadioButton(this);
rd.setText(acp.ID + ": " + acp.Name);
rd.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
onRadioButtonClicked(v);
}
});
rg.addView(rd);
}
rlaAccessPoints.addView(rg);
for (int i = 0; i <= rg.getChildCount() - 1; i++){
RadioButton rd = new RadioButton(this);
rd = (RadioButton)rg.getChildAt(i);
String rdText = rd.getText().toString();
int colonPos = rdText.indexOf(":");
rdText = rdText.substring(0, colonPos).toString();
if (Settings.AccessPointID.equals(rdText)){
//rg.check(i);
rd.setChecked(true);
}
}
}
EDIT: I posted an answer below with much more concise code; please look at that instead.