android - 如何在android中选中两个未选中的复选框

标签 android

你好,我是 Android 初学者。我在我的项目中使用了四个复选框。我想在 3 号和 4 号复选框处于未选中状态后调用一种方法。如何编写该代码请帮助我。

提前致谢。

class myCheckBoxChnageClicker implements CompoundButton.OnCheckedChangeListener {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            // Is the view now checked?
            boolean checked = ((CheckBox) buttonView).isChecked();


            // Check which checkbox was clicked
            switch(buttonView.getId()) {

                case R.id.t3_check:

                    if (checked) {



                    } else {


                    }

                    break;

                case R.id.t4_check:

                    if (checked) {



                    } else {



                    }

                    break;

                case R.id.tsh_check:

                    if (checked) {



                    } else {


                    }

                    break;

                case R.id.weight_check:

                    if(checked) {



                    } else {



                    }

                    break;
                default:

            }







        }

        public void showTextNotification(String msgToDisplay) {


            if ((msgToDisplay.equals("Tsh_Check") && msgToDisplay.equals("Weight_Check"))) {

                Toast.makeText(getApplicationContext(), "match", Toast.LENGTH_SHORT).show();

            } else {


            }


        }
    }

您好,这是我的代码,当 3 和 4 复选框处于未选中状态时,我想调用 showTextNotification() 方法。

最佳答案

试试这个。

 final boolean Check_three = false;
 final boolean Check_foure  = false;

        class myCheckBoxChnageClicker implements CompoundButton.OnCheckedChangeListener {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                // Is the view now checked?
                boolean checked = ((CheckBox) buttonView).isChecked();


                // Check which checkbox was clicked
                switch(buttonView.getId()) {

                    case R.id.t3_check:

                        if (checked) {
                            Check_three = true;

                            if (Check_three == true && Check_foure == true)
                            {
                                showTextNotification("printmeaage");  
                            }


                        } else {
                            Check_three = false;

                        }

                        break;

                    case R.id.t4_check:

                        if (checked) {

                            Check_foure = true;
                            if (Check_three == true && Check_foure == true)
                            {
                                showTextNotification("printmeaage");
                            }

                        } else {

                            Check_foure = false;

                        }

                        break;

                    case R.id.tsh_check:

                        if (checked) {



                        } else {


                        }

                        break;

                    case R.id.weight_check:

                        if(checked) {



                        } else {



                        }

                        break;
                    default:

                }


            }

关于android - 如何在android中选中两个未选中的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47300801/

相关文章:

android - 在应用程序启动时立即隐藏状态和导航栏

java - 如何创建行之间具有不同背景的警报对话框列表

android - FCM token 是否特定于应用程序或设备?

android - IntentService 中未收到广播接收器

安卓应用开发 : How to get Google Gmail account credentials to send email automatically?

android - OpenGL ES 2.0 : Filling in a Sphere instead of it being wireframe

java - 一段时间后如何做do/while?

android - 向上导航按钮在首选项 Activity 中不起作用

android - 无法使用 Volley 从 Json 响应保存图像

java - 使部分图像可点击 (Android)