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

问题描述 投票:0回答:2

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

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

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

但是使用这种语法我有一个错误:android.content.res.Resources $ NotFoundException:字符串资源ID#0xfe1e0079

java android settext
2个回答
1
投票

价值: 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);

1
投票

试试这个:

 mytext.setText(resources.getString(R.string.history_text1) + resources.getString(R.string.history_text2))
© www.soinside.com 2019 - 2024. All rights reserved.