I have radio button for the user to choose if he/she wants to keep his/her account logged in.
How do I assign SharedPreferences on the radiobutton? Please I r开发者_如何学编程eally need help.
This should work ...
SharedPreferences pref = getSharedPreferences("preferencesName", MODE_PRIVATE);
final SharedPreferences.Editor prefEdit = pref.edit();
RadioButton radio = (RadioButton) findViewById(R.id.radio);
radio.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
prefEdit.putBoolean("booleanValue", isChecked).commit();
}
});
the above code is for putting the value of radio button through shared preferences and for reading value of radio button whether it is checked or not , use the following code
SharedPreferences prefs = activity.getSharedPreferences("preferencesName", Activity.MODE_PRIVATE);
Boolean value= prefs.getBoolean(booleanValue, false);
精彩评论