Android Switch - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Switch class.

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: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:setChecked, setEnabled
    } 
 
    @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);
        } 
        mActionBarSwitch.setEnabled(true);
    } 
} 
8
CodeRank
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:isChecked, setChecked
        /* Stub! */ 
        return; 
    } 
 
    private void setSwitchChecked(boolean checked) {
        if (checked != mSwitch.isChecked()) {
            mStateMachineEvent = true;
            mSwitch.setChecked(checked);
            mStateMachineEvent = false;
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:setChecked, setEnabled
    } 
 
    @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);
        } 
        mActionBarSwitch.setEnabled(true);
    } 
} 
7
CodeRank
This code example shows how to use the following methods:setOnCheckedChangeListener
        mContext = context;
        mSwitch = switch_;
    } 
 
    public void resume() { 
        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(); 
    } 
6
CodeRank
This code example shows how to use the following methods:isChecked
    @Override 
    public void reloadPreference() { 
    } 
 
    private void updateInputState() { 
        if (mTimeLapseSwitch.isChecked()) {
            int newId = mUnitSpinner.getValue() * (mNumberSpinner.getMaxValue() + 1)
                    + mNumberSpinner.getValue() + 1;
            mPreference.setValueIndex(newId);
        } else { 
            mPreference.setValueIndex(0);
        } 
 
        if (mListener != null) {
            mListener.onListPrefChanged(mPreference);
        } 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:isChecked, setChecked
        /* Stub! */ 
        return; 
    } 
 
    private void setSwitchChecked(boolean checked) {
        if (checked != mSwitch.isChecked()) {
            mStateMachineEvent = true;
            mSwitch.setChecked(checked);
            mStateMachineEvent = false;
        } 
    } 
} 
6
CodeRank

Related Android Switch Questions & Answers:

See Code Examples for Android Switch Methods: