Android 存储 SP存储
给出关键代码
public void save(View view) { //获取Editor SharedPreferences.Editor editor = sp.edit(); //获取key和value String key = keyTextView.getText().toString(); String value = valueTextView.getText().toString(); //保存 editor.putString(key,value).commit(); //给出提示 Toast.makeText(this,"保存成功",Toast.LENGTH_SHORT).show(); } public void read(View view) { //获得key String key = keyTextView.getText().toString(); //获取value String value= sp.getString(key,null); //处理获得的value if(value!=null){ valueTextView.setText(value); }else{ Toast.makeText(this,"key不存在",Toast.LENGTH_SHORT).show(); } }