I have a few checkboxes within a dialog window. I want to save the checkboxes, after the customer confirmed with a button, that he want to save those settings. I tried to realize the code above, I cant find a way where I have to declerate the boolean's check1 and check2. Hope anyone can help me, if you need more information, please ask.
protected void onCreate(Bundle savedInstanceState) {
// ....
SharedPreferences prefs = getSharedPreferences("testSave", 0);
checkbox1.setChecked(prefs.getBoolean("cbx1_ischecked" ,false));
checkbox2.setChecked(prefs.getBoolean("cbx2_ischecked" ,false));
// ...
checkbox1.setOnCheckedChangeListener(new OnCheckedChangeListener(){
public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
// TODO Auto-generated method stub
check1=isChecked;
}
});
checkbox2.setOnCheckedChangeListener(new OnCheckedChangeListener(){
public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
// TODO Auto-generated method stub
check2=isChecked;
}
});
buttonSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Editor editor = getSharedPreferences("testSave", 0).edit();
editor.putBoolean("cbx1_ischecked", check1);
editor.putBoolean("cbx2_ischecked", check2);
editor.commit();
}
});
});
Aucun commentaire:
Enregistrer un commentaire