Code example for CheckBoxPreference

Methods: isChecked, setChecked

0
     * This is a simple example of controlling a preference from code. 
     */ 
    private Runnable mForceCheckBoxRunnable = new Runnable() {
        public void run() { 
            if (mCheckBoxPreference != null) { 
                mCheckBoxPreference.setChecked(!mCheckBoxPreference.isChecked()); 
            } 
             
            // Force toggle again in a second 
            mHandler.postDelayed(this, 1000); 
        } 
    }; 
     
    @Override 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        // Load the XML preferences file 
        addPreferencesFromResource(R.xml.advanced_preferences);
         
        // Get a reference to the checkbox preference