【使用SharedPreferences进行数据存储】
1 public void save(View v) 2 { 3 String name = nameText.getText().toString(); 4 String age = ageText.getText().toString(); 5 6 service.save(name, Integer.valueOf(age)); 7 Toast.makeText(getApplicationContext(), R.string.success, 1).show(); 8 }
1 public class PreSharedPreferences { 2 private Context context; 3 public PreSharedPreferences(Context context) { 4 this.context = context; 5 } 6 /** 7 * 保存参数,姓名,年龄 8 * @param name 9 * @param valueOf 10 */ 11 public void save(String name, Integer valueOf) { 12 // TODO Auto-generated method stub 13 SharedPreferences preferences = context.getSharedPreferences("danale", Context.MODE_PRIVATE); 14 Editor editor = preferences.edit(); 15 editor.putString("name", name); 16 editor.putInt("age", valueOf); 17 editor.commit(); 18 } 19 20 }