Code example for CheckBox

Methods: getContextisCheckedsetCheckedsetOnCheckedChangeListener

     * we will care for persistence - means on checked change there happens some save and on init set the state 
     * @param tag - setting is bound to tag - same tag same setting 
    public void careForCheckedStatePersistence(final String tag) {
        final SharedPreferences mSharedPrefs = checkBox.getContext().getSharedPreferences("ui_state", Context.MODE_WORLD_READABLE);
        checkBox.setChecked(mSharedPrefs.getBoolean(tag, checkBox.isChecked()));
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mSharedPrefs.edit().putBoolean(tag, isChecked).commit();
Contextual code suggestions in your IDE  Get Codota for Java