将 int 与字符串连接到 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值,您需要在ResourcesContext实例上调用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 

最新更新