Android 一次检查多个放射组已更改
这是我第一次参加广播小组。我正在尝试将3个组的值保存到共享优先级。它只适用于一个组,但一旦我尝试再添加两个组,所有pref值都只是表单中的最后一个组。我不知道如何使用多个放射组。任何帮助都将不胜感激 一次创建Android 一次检查多个放射组已更改,android,android-radiogroup,Android,Android Radiogroup,这是我第一次参加广播小组。我正在尝试将3个组的值保存到共享优先级。它只适用于一个组,但一旦我尝试再添加两个组,所有pref值都只是表单中的最后一个组。我不知道如何使用多个放射组。任何帮助都将不胜感激 一次创建 RadioGroup radioGroupGender = (RadioGroup) findViewById(R.id.gender_radio); radioGroupGender.setOnCheckedChangeListener(this); RadioGroup radioG
RadioGroup radioGroupGender = (RadioGroup) findViewById(R.id.gender_radio);
radioGroupGender.setOnCheckedChangeListener(this);
RadioGroup radioGroupActivity = (RadioGroup) findViewById(R.id.activity_level);
radioGroupActivity.setOnCheckedChangeListener(this);
RadioGroup radioGroupStatus = (RadioGroup) findViewById(R.id.current_status);
radioGroupStatus.setOnCheckedChangeListener(this);
我的一次检查改变了
public void onCheckedChanged(RadioGroup radioGroup, int i) {
int genderId = radioGroup.getCheckedRadioButtonId();
RadioButton genderBut = (RadioButton)radioGroup.findViewById(genderId);
gender_radio = genderBut.getText().toString();
int activityLvl = radioGroup.getCheckedRadioButtonId();
RadioButton activityLvlBut = (RadioButton)radioGroup.findViewById(activityLvl);
activity_level = activityLvlBut.getText().toString();
int currentStat = radioGroup.getCheckedRadioButtonId();
RadioButton CurrentBut = (RadioButton)radioGroup.findViewById(currentStat);
current_status = CurrentBut.getText().toString();
}
您正在使用相同的
gender\u收音机
活动级别
当前状态
,它们在每次调用onCheckedChanged()
时都会被覆盖,只有上次调用onCheckedChanged()
的值会被保存您正在调用的findViewById()
对于传递到onCheckedChanged()
的radioGroup
参数上的每个单选按钮
。该参数将是当前正在更改的RadioGroup
。您需要在特定组中查找给定组的已检查ID;e、 第一个是RadioButton-genderBut=(RadioButton)radiogroup-gender.findViewById(genderId)代码>。