【问题标题】:Change Visibility with CheckBox - Android使用 CheckBox 更改可见性 - Android
【发布时间】:2014-05-11 19:18:15
【问题描述】:

我想根据选中的 CheckBoxes 更改 ProgressBar 的可见性,但是当我实现以下代码时,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);
    }

【问题讨论】:

    标签: android checkbox progress-bar visibility


    【解决方案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);
                            }
                    }
    
            });
    

    【讨论】:

    • 请编辑您的答案,它不适合我的代码。
    猜你喜欢
    • 1970-01-01
    • 2017-08-04
    • 2017-07-25
    • 2014-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-14
    • 2023-03-23
    相关资源
    最近更新 更多