CompoundButton setOnCheckedChangeListener - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for CompoundButton setOnCheckedChangeListener method.

This code example shows how to use the following methods:setId, setLayoutParams, setChecked, setOnCheckedChangeListener
				RelativeLayout.LayoutParams.WRAP_CONTENT,
				RelativeLayout.LayoutParams.WRAP_CONTENT);
		checkboxparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
		checkboxparams.addRule(RelativeLayout.CENTER_VERTICAL);
 
		checkbox = new CheckBox(getContext());
		checkbox.setLayoutParams(checkboxparams);
		checkbox.setOnCheckedChangeListener(this);
		checkbox.setId(CHECKBOX_ID);
		 
		 
 
		layout.addView(title);
		layout.addView(description);
		layout.addView(checkbox);
		layout.setId(android.R.id.widget_frame);
 
		checkService(); 
		 
		return layout;

7
CodeRank
This code example shows how to use the following methods:isChecked, setOnCheckedChangeListener, setChecked
                mSwitch.setEnabled(true);
        } 
    } 
 
    private void setChecked(boolean isChecked) {
        if (isChecked != mSwitch.isChecked()) {
            // set listener to null, so onCheckedChanged won't be called 
            // if the checked status on Switch isn't changed by user click 
            if (mValidListener) {
                mSwitch.setOnCheckedChangeListener(null);
            } 
            mSwitch.setChecked(isChecked);
            if (mValidListener) {
                mSwitch.setOnCheckedChangeListener(this);
            } 
        } 
    } 
} 
8
CodeRank
This code example shows how to use the following methods:isChecked, setOnCheckedChangeListener, setChecked, setEnabled
            case BluetoothAdapter.STATE_TURNING_OFF:
                mSwitch.setEnabled(false);
                break; 
            case BluetoothAdapter.STATE_OFF:
                setChecked(false); 
                mSwitch.setEnabled(true);
                break; 
            default: 
                setChecked(false); 
                mSwitch.setEnabled(true);
        } 
    } 
 
    private void setChecked(boolean isChecked) {
        if (isChecked != mSwitch.isChecked()) {
            // set listener to null, so onCheckedChanged won't be called 
            // if the checked status on Switch isn't changed by user click 
            if (mValidListener) {
                mSwitch.setOnCheckedChangeListener(null);
            } 

8
CodeRank
This code example shows how to use the following methods:setTag, setChecked, setOnCheckedChangeListener
    } 
 
    private void initItemCheckbox(int position, ViewGroup view) {
        CheckBox checkBox = (CheckBox) view.findViewById(android.R.id.checkbox);
        boolean selected = isSelected(position);
        checkBox.setTag(position);
        checkBox.setChecked(selected);
        checkBox.setOnCheckedChangeListener(this);
    } 
 
    @SuppressWarnings("deprecation") 
    private void updateItemBackground(int position, View v) {
        long handle = positionToSelectionHandle(position);
        boolean selected = isSelected(handle);
        Drawable bg = selected ? selectedItemBackground : unselectedItemBackground;
        v.setBackgroundDrawable(bg);
    } 
     
    @Override 
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
7
CodeRank
This code example shows how to use the following methods:setChecked, setOnCheckedChangeListener, setText
    { 
        return ((Tag) getItem(position)).getTag().hashCode();
    } 
 
    public void initTagCheckbox(Tag tag, CheckBox checkBox) {
        checkBox.setText(tag.getTag());
        checkBox.setOnCheckedChangeListener(null);
        checkBox.setChecked(isChecked(tag.getTag()));
        checkBox.setOnCheckedChangeListener(this);
    } 
 
    @Override 
    public void onCheckedChanged(CompoundButton buttonView,
            boolean isChecked) {
 
        String text = (String) buttonView.getText();
        if (isChecked)
            checkedTags.add(text);
        else 
            checkedTags.remove(text);
7
CodeRank
This code example shows how to use the following methods:setOnCheckedChangeListener
    public void resume() { 
        mSwitch.setOnCheckedChangeListener(this);
    } 
 
    public void pause() { 
        mSwitch.setOnCheckedChangeListener(null);
    } 
 
    public void setSwitch(Switch switch_) {
        /* Stub! */ 
        if (mSwitch == switch_)
            return; 
        mSwitch.setOnCheckedChangeListener(null);
        mSwitch = switch_;
        mSwitch.setOnCheckedChangeListener(this);
 
        setState(switch_);
    } 
 
    public void setState(Switch switch_) {
6
CodeRank
This code example shows how to use the following methods:setLayoutParams, setOnCheckedChangeListener, setSelected
This code example shows how to use the following methods:isChecked, setOnCheckedChangeListener, setChecked
    } 
 
    public void resume() { 
        mPrefs.registerOnSharedPreferenceChangeListener(this);
        setSwitchChecked(mPrefs.getBoolean(mKey, mDefValue));
        mSwitch.setOnCheckedChangeListener(this);
    } 
 
    @Override 
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
        if (key.equals(mKey)) {
            setSwitchChecked(sharedPreferences.getBoolean(mKey, mDefValue));
        } 
    } 
 
    private void setSwitchChecked(boolean checked) {
        if (checked != mSwitch.isChecked()) {
            mStateMachineEvent = true;
            mSwitch.setChecked(checked);
            mStateMachineEvent = false;

8
CodeRank
This code example shows how to use the following methods:setOnCheckedChangeListener
        mSwitch.setOnCheckedChangeListener(this);
        setSwitchState(); 
    } 
 
    public void pause() { 
        mSwitch.setOnCheckedChangeListener(null);
    } 
 
    public void setSwitch(Switch switch_) {
        if (mSwitch == switch_) return;
        mSwitch.setOnCheckedChangeListener(null);
        mSwitch = switch_;
        mSwitch.setOnCheckedChangeListener(this);
        setSwitchState(); 
    } 
 
    private void setSwitchState() { 
        boolean enabled = Settings.System.getInt(mContext.getContentResolver(),
                Settings.System.SYSTEM_PROFILES_ENABLED, 1) == 1; 
        mStateMachineEvent = true;
6
CodeRank
This code example shows how to use the following methods:setOnCheckedChangeListener, setChecked
            getActivity().getActionBar().setTitle(mOldActivityTitle);
        } 
    } 
 
    private void initView(View view) {
        mActionBarSwitch.setOnCheckedChangeListener(this);
        mActionBarSwitch.setChecked(mNfcAdapter.isNdefPushEnabled());
    } 
 
    @Override 
    public void onCheckedChanged(CompoundButton buttonView, boolean desiredState) {
        boolean success = false;
        mActionBarSwitch.setEnabled(false);
        if (desiredState) {
            success = mNfcAdapter.enableNdefPush();
        } else { 
            success = mNfcAdapter.disableNdefPush();
        } 
        if (success) {
            mActionBarSwitch.setChecked(desiredState);
7
CodeRank

Related CompoundButton setOnCheckedChangeListener Questions & Answers:

setOnCheckedChangeListener Method Overview
Register a callback to be invoked when the checked state of this button changes.
See Code Examples for other Android CompoundButton Methods: