2011-05-20 38 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();