【发布时间】:2016-07-29 12:17:44
【问题描述】:
假设我的 Xamarin.Android 应用中有 EditText。我想从中获取文本并将其保存为 Strings.xml 中的字符串。我该怎么做?
【问题讨论】:
标签: c# android xml string xamarin
假设我的 Xamarin.Android 应用中有 EditText。我想从中获取文本并将其保存为 Strings.xml 中的字符串。我该怎么做?
【问题讨论】:
标签: c# android xml string xamarin
strings.xml 不能以编程方式修改。它们是常量字符串。
如果您需要保存字符串并保留它,最简单的方法是使用 SharedPreferences 将值存储为键值对。试试看
ISharedPreferences sharedprefs = GetSharedPreferences("prefs_file", FileCreationMode.Private);
sharedprefs.Edit().PutString("keyName","value").Commit();
您可以使用“keyName”来检索字符串,例如
ISharedPreferences sharedprefs = GetSharedPreferences("prefs_file", FileCreationMode.Private);
String str = sharedprefs.GetString("keyName", null);
【讨论】: