开关状态更改不起作用-Android

开关状态更改不起作用-Android,android,Android,我试图通过点击另一个交换机来改变交换机的状态及其实现。我试过了,但失败了。 有人能帮忙吗 这是我的Activity.java //first switch flw_Rate_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, bool

我试图通过点击另一个交换机来改变交换机的状态及其实现。我试过了,但失败了。 有人能帮忙吗

这是我的Activity.java

//first switch

flw_Rate_switch.setOnCheckedChangeListener(new 

CompoundButton.OnCheckedChangeListener() {

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)  {

            if (isChecked) {

                    //lqd_followed_switch.setOnCheckedChangeListener(null);

          //lqd_followed_switch.setChecked(!lqd_followed_switch.isChecked());

                    flow_rate_switch_txt.setTextColor(Color.RED);

                    mlineData = generateLineData(rate);
                    data.setData(mlineData);
                    combinedChart.setData(data);

                    combinedChart.setVisibleXRangeMaximum(4); // allow 4 values to be displayed at once on the x-axis, not more
                    combinedChart.moveViewToX(4);
                    combinedChart.animateY(2000);
                    combinedChart.invalidate();


                } else {
                    //elseFlowRate();
                    flow_rate_switch_txt.setTextColor(Color.BLACK);
                    String label = "Flow Rate";

                    boolean indicator = data.removeDataSet(lineData1.getDataSetByLabel(label, true));
                    combinedChart.notifyDataSetChanged();
                    combinedChart.invalidate();
                    combinedChart.animateX(1000);
                }
            }

        });


//2nd switch


        lqd_followed_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {

                 lqd_followed_switch_txt.setTextColor(getColor(R.color.colorPrimary));



                    mlineData = generateLineData1(foll);
                    data.setData(mlineData);
                    combinedChart.setData(data);

                    combinedChart.setVisibleXRangeMaximum(4); // allow 4 values to be displayed at once on the x-axis, not more
                    combinedChart.moveViewToX(4);
                    combinedChart.animateY(2000);
                    combinedChart.invalidate();

                } else {

                    lqd_followed_switch_txt.setTextColor(Color.BLACK);

                    String label = "Liquid Followed";
                    boolean indicator = data.removeDataSet(lineData2.getDataSetByLabel(label, true));
                    combinedChart.notifyDataSetChanged();
                    combinedChart.invalidate();

                }
            }

        });
当我点击第一个开关时,它运行“如果”块,同时当我点击第二个开关时,它运行第二个开关的“如果”块,但它不能继续运行开关第一个“如果”子句块,而不是自动运行开关第一个的“其他”块

CompoundButton.OnCheckedChangeListener()
是一个事件侦听器,这意味着如果事件(已选中或未选中)未发生,则不会触发它

如果要更新其他UI组件,应调用如下内容:

flw\u Rate\u开关。设置检查(假);

flw\u Rate\u开关。设置已检查(真);

简而言之,问题在于,通过轻触第二个开关,第一个开关的“else”块也应该运行。