在strings.xml中获取值

时间:2014-02-22 08:54:40

标签: xamarin android-resources arrays

在Xamarin中,我在strings.xml文件中有以下内容:

<?xml version="1.0" encoding="utf-8"?>
<resources>

   <string name="app_name">AutoComplete</string>
   <string name="action_settings">Settings</string>
   <string name="hello_world">Hello world!</string>
   <string name="auto_complete">AutoComplete</string>
   <string name="multi_auto_complete">Multi AutoComplete</string>
   <string-array name="list_of_countries">
      <item >USA</item>
      <item >Uk</item>
      <item >Canada</item>
      <item >Australia</item>
      <item >France</item>
      <item >Italy</item>
      <item >China</item>
      <item >Japan</item>
      <item >Spain</item>
      </string-array>

</resources>    

如何将上述数据放入数组?

这是我当前的代码(不起作用):

String[] countries = Resources.GetStringArray (list_of_countries);

提前致谢

1 个答案:

答案 0 :(得分:5)

String[] countries = Resources.GetStringArray(Resource.Array.list_of_countries);

Strings.xml的路径:

Resources/values/Strings.xml

我希望这会有所帮助!