如何轻松地遍历"strings.xml"中的所有字符串.资源文件? [英] How to easily iterate over all strings within the "strings.xml" resource file?

查看:341
本文介绍了如何轻松地遍历"strings.xml"中的所有字符串.资源文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个使用TTS引擎向用户发送反馈的应用程序.为了提高性能,我使用了synthesizeToFileaddSpeech方法,但是要合成的文本字符串位于strings.xml文件内部,因此我必须针对由TTS引擎.

I created an application that uses the TTS engine to send feedback to the user. With the aim to improve the performance, I used the synthesizeToFile and addSpeech methods, but strings of text to be synthesized are inside the strings.xml file, so I have to invoke these methods for each string that is spoken by the TTS engine.

由于TTS引擎仅使用名称以tts_开头的字符串,是否可以轻松地遍历strings.xml文件中以tts_开头的所有字符串?

Since the TTS engine uses only strings whose name begins with tts_, is it possible to easily iterate over all strings that begin with tts_ within the strings.xml file?

推荐答案

您可以(在定义时)将所有资源名称都指定为"prefix"+(1..n).在代码中,

You can give them all (while defining) the resource name as "prefix"+(1..n). And in the code use,

int resid=<constant>;
for(i=1;resid!=0;i++){
        resid = this.getResources().getIdentifier("prefix"+i, "strings", this.getPackageName());
}

这篇关于如何轻松地遍历"strings.xml"中的所有字符串.资源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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