将 int 与字符串连接到 TextView 给出了一组 Integer
Concatenation of int with string to TextView gives a set of Integer
在我的 android 应用程序中,我试图将文本设置为具有整数和字符串值的 TextView。我正在获取数组的长度并将其设置为如下所示的字符串值。
if (array.size() > 0) {
textView.setText(array.size() + " " + R.string.lbl_text);
}
当我 运行 应用程序时,它会给我一组整数,如下所示:
1 2345223232
然后我将数组大小转换为字符串,如下所示
if (array.size() > 0) {
textView.setText(Integer.toString(array.size()) + " " + R.string.lbl_text);
}
但输出相同。为 string.lbl_text
获取整数值的原因是什么
R.string.xxx
是一个资源标识符。为了将其转换为 String
值,您需要在 Resources
或 Context
实例上调用 getString()
:
resources.getString(R.string.xxx);
Use getResources().getString(R.string.lbl_text) and then you would be able to access the string text. as @pskink told already
在我的 android 应用程序中,我试图将文本设置为具有整数和字符串值的 TextView。我正在获取数组的长度并将其设置为如下所示的字符串值。
if (array.size() > 0) {
textView.setText(array.size() + " " + R.string.lbl_text);
}
当我 运行 应用程序时,它会给我一组整数,如下所示:
1 2345223232
然后我将数组大小转换为字符串,如下所示
if (array.size() > 0) {
textView.setText(Integer.toString(array.size()) + " " + R.string.lbl_text);
}
但输出相同。为 string.lbl_text
R.string.xxx
是一个资源标识符。为了将其转换为 String
值,您需要在 Resources
或 Context
实例上调用 getString()
:
resources.getString(R.string.xxx);
Use getResources().getString(R.string.lbl_text) and then you would be able to access the string text. as @pskink told already