Android TextView : “Do not concatenate text displayed with setText”

时间:2022-05-04 23:31:50

参考:http://*.com/questions/33164886/android-textview-do-not-concatenate-text-displayed-with-settext

在Activity中对TextView进行动态更新显示数据时,如果使用:

RGB_textview.setText(settingData.Image_R + "," + settingData.Image_G + "," + settingData.Image_B);

则Android Studio 会提示:“Do not concatenate text displayed with setText,use resource string with placeholders”,

应改为:

RGB_textview.setText(getString(R.string.RGB_value_string, settingData.Image_R, settingData.Image_G, settingData.Image_B));
<string name="RGB_value_string">%1$d,%2$d,%3$d</string>

不修改也能正常运行,但修改一下会更加规范。