如何在android中获取单选按钮的选定(整数)id

时间:2014-02-25 09:12:27

标签: android radio-button

但是我得到了唯一的身份证,但不知道如何获得像1,2这样的身份证...我已经在下面发布了我的代码......

public void onCheckedChanged(RadioGroup group, int checkedId){      
    Global.id=(int)buttongroup.getCheckedRadioButtonId();               
    System.out.println("selected Global Id:"+Global.id);                
    System.out.println("selected id"+Global.id);                
    btn=(RadioButton)findViewById(Global.id);               
    btn.setChecked(true);               
    Global.buttonname=(String)btn.getText();                
    System.out.println("selected radio button"+Global.buttonname);              
}

02-25 14:59:38.042:I / System.out(8717):已选择全球ID:2131427346

02-25 14:59:38.042:I / System.out(8717):已选择id2131427346

2 个答案:

答案 0 :(得分:2)

你可以打开id:

switch(checkedId) {
  case R.id.name_of_fist_radiobutton:
   /// my operation form 1;
   break;
   case R.id.name_of_second_radiobutton:
   /// my operation form 2;
   break;
}

答案 1 :(得分:0)

试试这个来获得价值:

String radiovalue=  (RadioButton)this.findViewById(group.getCheckedRadioButtonId())).getText().toString();