2011-05-20 58 views

回答

4
static SharedPreferences settings; 
static SharedPreferences.Editor editor; 
settings = this.getPreferences(MODE_WORLD_WRITEABLE); 
editor = settings.edit(); 
editor.putString("Variablenname_1", "1"); 
editor.commit(); 

,如果你想这样得到的数值使用:

String val = settings.getString("Variablenname_1", "0"); 
+0

谢谢,我打算尝试使用FileOutputStream fos = openFileOutput – fr4n 2011-05-20 09:39:41

+0

您只能在首选项中存储simle数据类型,如果您有fos,为什么不将它存储为File? – 2red13 2011-05-20 09:47:41

0

的最终结果。

SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(this); 
String text = app_preferences.getString("name", "default"); 
... 

SharedPreferences.Editor editor = app_preferences.edit(); 
editor.putString("name",name.getText().toString()); 
editor.commit();