使用片段调用可见性-Android

使用片段调用可见性-Android,android,fragment,visibility,Android,Fragment,Visibility,我的项目中有两个活动,Activity_one.xml包含ProgressBar和复选框,我知道我可以从同一个活动调用visibility方法,但我想在Activity_one.java中实现visibility方法。我听说可以通过使用片段来实现,但我不知道如何做到这一点 progressBar1 = (ProgressBar) findViewById(R.id.progressBar1); progressBar2 = (ProgressBar) findViewById(R.id.prog

我的项目中有两个活动,Activity_one.xml包含ProgressBar和复选框,我知道我可以从同一个活动调用visibility方法,但我想在Activity_one.java中实现visibility方法。我听说可以通过使用片段来实现,但我不知道如何做到这一点

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);
 }

}

问题是如何使用碎片?也许,因为我对碎片还不熟悉