Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.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
Java 使用单选按钮切换相对布局可见性_Java_Android_Android Studio - Fatal编程技术网

Java 使用单选按钮切换相对布局可见性

Java 使用单选按钮切换相对布局可见性,java,android,android-studio,Java,Android,Android Studio,我遇到了一个奇怪的问题: 我一直在制作我的第一个android应用程序——一个简单的体脂计算器。其中一项功能要求,如果用户选择其性别为“男性”,则需要输入髋部周长的布局应不可见。反之亦然。问题是,当选中“男性”单选按钮时,布局确实会消失,但当选中“女性”单选按钮时,视图不会返回!为什么? 选择单选按钮并相应地设置可见性 genderGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

我遇到了一个奇怪的问题: 我一直在制作我的第一个android应用程序——一个简单的体脂计算器。其中一项功能要求,如果用户选择其性别为“男性”,则需要输入髋部周长的布局应不可见。反之亦然。问题是,当选中“男性”单选按钮时,布局确实会消失,但当选中“女性”单选按钮时,视图不会返回!为什么?


选择单选按钮并相应地设置可见性

genderGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                for (int rb_index=0;rb_index<genderGroup.getChildCount();rb_index++)
                {
                    Log.e("RADIOBUTTON :",""+rb_index+"/"+genderGroup.getChildCount());

                    RadioButton rb=((RadioButton) genderGroup.getChildAt(rb_index));
                    if(rb.isChecked()&&rb.getTag().toString().equalsIgnoreCase("male")){
                        Log.e("RADIOBUTTON :"," OK "+rb_index);

                         hip_layout.setVisibility(View.VISIBLE);
                    }
                      if(rb.isChecked()&&rb.getTag().toString().equalsIgnoreCase("female")){

                          hip_layout.setVisibility(View.INVISIBLE);
                    }
                }


            }
        });
genderGroup.setOnCheckedChangeListener(新的RadioGroup.OnCheckedChangeListener(){
@凌驾
检查更改后的公共无效(放射组放射组,int i){

对于(int rb_index=0;rb_indexhip_layout.setVisibility(View.INVISIBLE)/hip_layout.setVisibility(View.VISIBLE)getCheckedRadioButtonId()在哪里?我还发现我错误地使用了“==”,而不是.equals(),现在一切都正常了!谢谢大家!老兄!!非常感谢!!
genderGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                for (int rb_index=0;rb_index<genderGroup.getChildCount();rb_index++)
                {
                    Log.e("RADIOBUTTON :",""+rb_index+"/"+genderGroup.getChildCount());

                    RadioButton rb=((RadioButton) genderGroup.getChildAt(rb_index));
                    if(rb.isChecked()&&rb.getTag().toString().equalsIgnoreCase("male")){
                        Log.e("RADIOBUTTON :"," OK "+rb_index);

                         hip_layout.setVisibility(View.VISIBLE);
                    }
                      if(rb.isChecked()&&rb.getTag().toString().equalsIgnoreCase("female")){

                          hip_layout.setVisibility(View.INVISIBLE);
                    }
                }


            }
        });
<RadioGroup
    android:layout_width="wrap_content"
    android:id="@+id/rdg"
    android:layout_height="wrap_content">

    <RadioButton
        android:id="@+id/male"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:tag="male"
        android:text="Male"/>
 <RadioButton
     android:id="@+id/female"
     android:tag="female"

     android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Female"/>
</RadioGroup>