您的位置:首页 > 移动开发 > Android开发

Android25图灵聊天项目------在代码中拿到资源文件string.xml中的数据

2015-06-06 17:39 513 查看


string.xml文件

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

<resources>

<string name="app_name">25图灵聊天</string>

<string name="action_settings">Settings</string>

<string name="hello_world">Hello world!</string>

<string name="send">发送</string>

<string-array name="welcome_tips">

<item>主人,奴婢在此等候多时了</item>

<item>主人,近来一切可好</item>

<item>亲爱的,我想死你了</item>

<item>欢迎归来,我亲爱的主人</item>

<item>我是图灵机器人,很高兴为您服务</item>

</string-array>

</resources>

/**

* 拿到string.xml中的数据,放到数组,随机取出

*

*

*/

private String getRandomWelcomeTips() {

String welcome_tip = null;

private String[] welcome_array = this.getResources().getStringArray(R.array.welcome_tips);

int index = (int) (Math.random() * (welcome_array.length - 1));

welcome_tip = welcome_array[index];

return welcome_tip;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: