I have a checkbox preference and I want to set it's value from another checkbox. Now I can get the value from the checkboxpreference and set it to the external checkbox but I didn't know how to set the preference value from that external checkbox.Any Help PleaseThis is my code
getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); musicpref = getPrefs.getBoolean("musicp", true);
CheckBox musiccheck = (CheckBox) findViewById(R.id.checkBox1);
//The external Checkbox, is checked will start service , if not will stop it
musiccheck.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
Intent musicstart = new Intent(MainActivity.this,
ServiceMusic.class);
startService(musicstart);
} else {
Intent musicstart = new Intent(MainActivity.this,
ServiceMusic.class);
stopService(musicstart);
}
}
});
// Preference checkbox , if is true will set the external checkbox to true
if (musicpref == true) {
musiccheck.setChecked(true);
}else{
musiccheck.setChecked(false);
}