2014-04-01 41 views
0

我要根據檢查的CheckBoxes改變ProgressBar的知名度,但是當我執行下面的代碼中,ProgressBar那張無形永遠使用複選框更改能見度 - Android電子

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

回答

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

     }); 
+0

請編輯你的答案,它不適合我的代碼。 –

+0

檢查編輯... – jyomin