Here are my questions:
1. To get the value of a switch:
CompoundButton cb = (CompoundButton)view.findViewById(R.id.myswitch);
if(cb.isChecked())
cb.setChecked(false);
else
cb.setChecked(true);
Reference: Toggle Buttons
2. Yes, the elements in a PreferenceFragment
are automatically stored.
3. To get the SharedPreference
object of a PreferenceFragment
, use:
getDefaultSharedPreferences(Context context)