【发布时间】:2017-04-30 02:11:25
【问题描述】:
嗨,我通常说我是 android 和语言的新手,我使用 SharedPreferences 来存储不同的编辑文本,但现在我想存储一个复选框的检查,但我不知道如何存储这个值,我希望有人可以帮助我。
公共类 FiveFragment 扩展片段 {
EditText et133;
CheckBox ch1;
public FiveFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_five, container, false);
SharedPreferences setting = this.getActivity().getSharedPreferences("PRESS", Context.MODE_PRIVATE);
et133 = (EditText) view.findViewById(R.id.editText);
ch1 = (CheckBox) view.findViewById(R.id.checkBox);
//现在????
et133.setText(setting.getString("value133", ""));
return view;
}
public void onStop() {
super.onStop();
if (et133.getText() != null) {
SharedPreferences setting = this.getActivity().getSharedPreferences("PRESS", 0);
SharedPreferences.Editor editor = setting.edit();
editor.putString("value133", et133.getText().toString());
//现在??? editor.apply();
}
}
}
【问题讨论】:
标签: android android-fragments sharedpreferences store android-sharedpreferences