0

我有一个包含两个单选按钮(自我交付和公司交付)的单选组的申请表。在插入详细信息时,一切正常,我可以通过以下代码获得单选按钮的文本:

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 并使收音机组在编辑页面中被选中。

4

1 回答 1

1
// 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);
        }
于 2013-10-04T05:25:32.060 回答