- public void saveToSharedPreference(View v){
- sp = this.getSharedPreferences("config.txt", Context.MODE_PRIVATE);
- //得到sharedpreference的编辑器
- SharedPreferences.Editor editor = sp.edit();
- editor.putString("title","www.sharejs.com");
- editor.putBoolean("success",true);
- //提交数据
- editor.commit();
- Toast.makeText(this,"保存到sharedpreference成功",Toast.LENGTH_SHORT).show();
- //读取SharePreference的内容
- String tel = sp.getString("title","没有获取到值");
- Toast.makeText(this,tel,Toast.LENGTH_SHORT).show();
- }
来源: http://www.phpxs.com/code/1002179/