2011-08-05 25 views
1

我想保存一些設置,但我正在遵循的教程(android教程)沒有幫助,因爲我卡在代碼的第一行,因爲它似乎monodroid做它不同?如何使用monodroid保存個人偏好?

   select your mode to be either private or public. 

int mode= Activity.MODE.PRIVATE; 

// get the sharedPreference of your context. 

SharedPreference s mySharedPreferences ; mySharedPreferences=getSharedPreferences(「Name_of_your_preference」,mode); 

// retrieve an editor to modify the shared preferences 

SharedPreferences.Editor editor= mySharedPreferences.edit(); 

/* now store your primitive type values. In this case it is true, 1f and Hello! World */ 

editor.putBolean(「myBoolean」,true); 

editor.putFloat(「myFloat」,1f); 

editor.putString(「myString」,」 Hello! World」); 

//save the changes that you made 

editor.commit(); 

我沒有在monodroid中看到Activity.MODE.PRIVATE;

回答

6

這裏是我的FUNC做到這一點:

protected void SaveSetting(string name, string value) 
    { 
     var prefences = GetSharedPreferences(Consts.Application.SETTINGS_FILE, FileCreationMode.Private); 
     var editor = prefences.Edit(); 
     editor.Remove(name); 
     editor.PutString(name, value); 
     editor.Commit(); 
    } 
3

假設你的意思是MODE_PRIVATE,它應該是Android.Content.FileCreationMode.Private。

幸運的是,您並不需要知道這一點,因爲我們將GetSharedPreferences中的int映射爲Android.Content.FileCreationMode枚舉,因此intellisense應該可以幫助您。