从零开始的体温app开发(sharedPreferences)
if(sharedPreferences==null){
sharedPreferences=getApplicationContext().getSharedPreferences("data", Context.MODE_PRIVATE);}
editText0.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
SharedPreferences.Editor edit=sharedPreferences.edit();
edit.putString("Name",editText0.getText().toString());
edit.commit();
}
});
public void initData(){
if(sharedPreferences==null){
sharedPreferences=getApplicationContext().getSharedPreferences("data", Context.MODE_PRIVATE);}
editText0.setText(sharedPreferences.getString("name",""));
editText5.setText(sharedPreferences.getString("num",""));
editText6.setText(sharedPreferences.getString("cl",""));
}