猿问

setText() 来自xml的多个字符串

也许是一个简单的问题 - 我需要帮助从我的 strings.xml 中设置多个字符串。

 mytext.setText(resources.getString(R.string.history_text1+R.string.history_text2));

所以我的意思是我需要通过一个 setText 将 2 个不同的文本作为一个文本。

但是使用这种语法我有一个错误:android.content.res.Resources$NotFoundException: String resource ID #0xfe1e0079


HUWWW
浏览 176回答 2
2回答

宝慕林4294392

尝试这个: mytext.setText(resources.getString(R.string.history_text1) + resources.getString(R.string.history_text2))

叮当猫咪

值:R.string.history_text1和R.string.history_text2是引用资源中实际字符串的整数。通过添加它们,您会得到另一个不引用任何内容的整数,因此您会得到:Resources$NotFoundException如果要连接 2 个字符串值:String value = resources.getString(R.string.history_text1) + resources.getString(R.string.history_text2) mytext.setText(value);
随时随地看视频慕课网APP

相关分类

Java
我要回答