我想根据选中的ProgressBar
更改CheckBoxes
的可见性,但是当我实施以下代码时,ProgressBar
将永远隐身
ProgressBar progressBar1 = (ProgressBar) findViewById(R.id.progressBar1);
ProgressBar progressBar2 = (ProgressBar) findViewById(R.id.progressBar2);
CheckBox checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
CheckBox checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
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 :(得分:1)
you have to set the visibility code in the setOnClick listener of the checkbox
checkBox1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(checkBox1.isChecked())
{
progressBar1.setVisibility(View.VISIBLE);
}
else
{
progressBar1.setVisibility(View.INVISIBLE);
}
}
});
checkBox2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(checkBox1.isChecked() && checkBox2.isChecked()) {
progressBar2.setVisibility(View.VISIBLE);
} else {
progressBar2.setVisibility(View.INVISIBLE);
}
}
});