为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

HUWWW 2022-06-23 10:32:42
也许是一个简单的问题 - 我需要帮助从我的 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
查看完整描述

2 回答

?
宝慕林4294392

TA贡献2021条经验 获得超8个赞

尝试这个:

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



查看完整回答
反对 回复 2022-06-23
?
叮当猫咪

TA贡献1776条经验 获得超12个赞

值:
R.string.history_text1R.string.history_text2
是引用资源中实际字符串的整数。
通过添加它们,您会得到另一个不引用任何内容的整数,因此您会得到:

Resources$NotFoundException

如果要连接 2 个字符串值:

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


查看完整回答
反对 回复 2022-06-23
  • 2 回答
  • 0 关注
  • 175 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号