Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 一次检查多个放射组已更改_Android_Android Radiogroup - Fatal编程技术网

Android 一次检查多个放射组已更改

Android 一次检查多个放射组已更改,android,android-radiogroup,Android,Android Radiogroup,这是我第一次参加广播小组。我正在尝试将3个组的值保存到共享优先级。它只适用于一个组,但一旦我尝试再添加两个组,所有pref值都只是表单中的最后一个组。我不知道如何使用多个放射组。任何帮助都将不胜感激 一次创建 RadioGroup radioGroupGender = (RadioGroup) findViewById(R.id.gender_radio); radioGroupGender.setOnCheckedChangeListener(this); RadioGroup radioG

这是我第一次参加广播小组。我正在尝试将3个组的值保存到共享优先级。它只适用于一个组,但一旦我尝试再添加两个组,所有pref值都只是表单中的最后一个组。我不知道如何使用多个放射组。任何帮助都将不胜感激

一次创建

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)