我有三个单选按钮来指定性别,男女和其他人。根据用户选择,我将这些数据保存到我的数据库中,其中男性为1,女性为2,其他为3。这反映在配置文件页面,现在当我想编辑配置文件时,我想以可编辑的方式自动填充我的配置文件页面的所有字段,用户只更改他想要的字段。虽然我可以从数据库中获取1,2,3的性别值,但我无法填充指定的单选按钮。我尝试了以下方法:单选按钮通过代码设置选中状态
String M = (c.getString(c.getColumnIndexOrThrow("Gender")));
RadioGroup rb1 = (RadioGroup)findViewById(R.id.radiogroup1);
if(M.equals(1)){
rb1.check(R.id.radiobutton3);
RadioButton rbu1 =(RadioButton)findViewById(R.id.radiobutton3);
rbu1.setChecked(true);
}
else if(M.equals(2)){
rb1.check(R.id.radiobutton4);
RadioButton rbu2 =(RadioButton)findViewById(R.id.radiobutton4);
rbu2.setChecked(true);
}
else if(M.equals(3)){
rb1.check(R.id.radiobutton5);
RadioButton rbu3 =(RadioButton)findViewById(R.id.radiobutton5);
rbu3.setChecked(true);
}
radiobutton.setSelected(真); – Syn3sthete