IneptusMechanicus
IneptusMechanicus

Reputation: 508

Xamarin android save string to strings.xml

Let's say I have and EditText in my Xamarin.Android app. I want to take the text from it and save it as a string in the Strings.xml . How do I do that?

Upvotes: 0

Views: 938

Answers (1)

Sujay
Sujay

Reputation: 3455

strings.xml cannot be modified programmatically. They are constant strings.

If you need to save a string & preserve it, simplest way is to use SharedPreferences to store value as key-value pairs. Try

ISharedPreferences sharedprefs = GetSharedPreferences("prefs_file", FileCreationMode.Private);
sharedprefs.Edit().PutString("keyName","value").Commit();

You can retrieve the string using "keyName" like

 ISharedPreferences sharedprefs = GetSharedPreferences("prefs_file", FileCreationMode.Private);
 String str = sharedprefs.GetString("keyName", null);

Upvotes: 3

Related Questions