从另一个活动调用可见性 - Android

时间:2014-04-13 11:49:11

标签: android visibility

我的项目中有两个活动,Activity_one.xml包含ProgressBar和复选框,我知道我可以从同一个活动调用可见性方法,但我想在Activity_two.java中实现可见性方法。我该怎么做?

progressBar1 = (ProgressBar) findViewById(R.id.progressBar1);
    progressBar2 = (ProgressBar) findViewById(R.id.progressBar2);
    checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
    checkBox2 = (CheckBox) findViewById(R.id.checkBox2);

    checkBox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            updateProgressBars();
        }
    });

    checkBox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            updateProgressBars();
        }
    });
    }

    public void updateProgressBars() {

      progressBar1.setVisibility(View.GONE);
      progressBar2.setVisibility(View.GONE);

     if (checkBox1.isChecked() && checkBox2.isChecked()) {
        progressBar2.setVisibility(View.VISIBLE);
     } else if (checkBox1.isChecked()) {
        progressBar1.setVisibility(View.VISIBLE);
     }

    }

0 个答案:

没有答案