>我有一个申请表,其中包含一个由两个单选按钮(自助交付和公司交付)组成的单选按钮。在插入详细信息时,一切正常,我可以使用以下代码选择单选按钮的文本:
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
selectedId = radioGroup.getCheckedRadioButtonId();
// find the radiobutton by returned id
radioButton = (RadioButton) findViewById(selectedId);
if (radioButton.isChecked()) {
OPTIONS=radioButton.getText().toString();
if (OPTIONS.equals("SelfDelivery")) {
deliveryAddress.setVisibility(View.GONE);
deliveryEdit.setVisibility(View.GONE);
} else {
deliveryAddress.setVisibility(View.VISIBLE);
deliveryEdit.setVisibility(View.VISIBLE);
}
}
}
});
当我按下编辑按钮并转到编辑页面时,我希望根据用户也选择单选按钮。例如:如果用户正在选择公司投放(在编辑页面中,应在单选按钮组中选择公司投放)。我不知道如何获取选定的id并在编辑页面中选择单选组。
// try this
// on edit try this way
RadioButton radioButtonSelf;
RadioButton radioButtonCompany;
radioButtonSelf = (RadioButton) findViewById(R.id.selfradiobuttonid);
radioButtonCompany = (RadioButton) findViewById(R.id.radioButtonCompany);
if(OPTIONS.equals("SelfDelivery")){
radioButtonSelf.setChecked(true);
radioButtonCompany.setChecked(false);
}else{
radioButtonCompany.setChecked(true);
radioButtonSelf.setChecked(false);
}