同じRadioGroup内の他のRadioButtonをクリックすると、以下の動的に生成されたRadioButtonのチェックを外すことができません。
RadioGroup (以下) をクリアする独自のハンドラーを作成し、すべての RadioButtons を .setChecked(false) にする別のハンドラーを作成しましたが、PopulateAccessPoints で setChecked した RadioButton はまだクリアされません。
何か案は?
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);
}
}
}
編集:より簡潔なコードで回答を以下に投稿しました。代わりにそれを見てください。