Code example for CheckBox

Methods: setEnabled, isChecked, setOnCheckedChangeListener

0
                        DataLiberationFragment.this,
                        mCheckBoxFullDump.isChecked(), false);
                mTask.execute();
            } 
        }); 
        mCheckBoxImportWarning.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override 
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mButtonImport.setEnabled(isChecked);
            } 
        }); 
        mButtonImport.setOnClickListener(new OnClickListener() {
            @Override 
            public void onClick(View v) {
                setProgressLock(true); 
 
                mTask = new JsonImportTask(context, DataLiberationFragment.this);
                mTask.execute();
            } 
        }); 
 
        // restore UI state 
        if (mTask != null && mTask.getStatus() != AsyncTask.Status.FINISHED) {
            setProgressLock(true); 
        } 
    } 
 
    @Override 
    public void onDestroy() { 
        if (mTask != null && mTask.getStatus() != AsyncTask.Status.FINISHED) {
            mTask.cancel(true);
        } 
        mTask = null;
 
        super.onDestroy(); 
    } 
 
    @Override 
    public void onProgressUpdate(Integer... values) {
        if (mProgressBar == null) {
            return; 
        } 
        mProgressBar.setIndeterminate(values[0] == values[1] ? true : false);
        mProgressBar.setMax(values[0]);
        mProgressBar.setProgress(values[1]);
    } 
 
    @Override 
    public void onTaskFinished() { 
        setProgressLock(false); 
    } 
 
    private void setProgressLock(boolean isLocked) {
        if (isLocked) {
            mButtonImport.setEnabled(false);
        } else { 
            mButtonImport.setEnabled(mCheckBoxImportWarning.isChecked());
        } 
        mButtonExport.setEnabled(!isLocked);
        mProgressBar.setVisibility(isLocked ? View.VISIBLE : View.GONE);
        mCheckBoxFullDump.setEnabled(!isLocked);
        mCheckBoxImportWarning.setEnabled(!isLocked);
    } 
 
}