存储阵列到XML文件 [英] Storing array into xml file

查看:125
本文介绍了存储阵列到XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个数组存储到一个XML文件中。

该阵列将被称为具有以下功能。

 字符串getTextSpeech = TextSpeech [索引]

这是使用textToSpeechAPI。

我怎么可以在阵列TextSpeech []保存在文件夹值一个xml文件,然后在类中调用它。

感谢

编辑:

 <资源>
<字符串数组名=myArray的>
    <项目> String1中< /项目>
    <项目> String2的< /项目>
    <项目>&STRING3 LT; /项目>
< /字符串数组>
< /资源>


解决方案

在活动可以调用它作为

 的String [] =资源字符串getResources()getStringArray(R.array.myArray)。

如果你的类是活动类型不是再使用类的构造器像

  YourClass(上下文activityContext)
{
     的String [] =资源字符串activityContext.getResources()getStringArray(R.array.myArray)。
}

I want to store an array into a xml file.

The array will be called with the following function.

String getTextSpeech = TextSpeech[Index];

This is using the textToSpeechAPI.

How can I store the array TextSpeech[] in an xml file in the values folder and then call it within the class.

Thanks

Edit:

<resources>
<string-array name="myArray"> 
    <item>String1</item> 
    <item>String2</item> 
    <item>String3</item> 
</string-array> 
</resources>

解决方案

In activity you can call it as

String[] resourceString =getResources().getStringArray(R.array.myArray);

if your class is not of an activity type then use a contructor of class like

YourClass(Context activityContext)
{
     String[] resourceString =activityContext.getResources().getStringArray(R.array.myArray);
}

这篇关于存储阵列到XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆