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

敢说敢作敢为, 无怨无恨无悔。这篇文章主要讲述Android TextView : “Do not concatenate text displayed with setText”相关的知识,希望能为你提供帮助。
参考:http://stackoverflow.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>

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


常用格式:
%n$s---> n表示目前是第几个参数 (比如%1$s中的1代表第一个参数),s代表字符串
%n$d---> n表示目前是第几个参数 (比如%1$d中的1代表第一个参数),d代表整数
%n$f---> n表示目前是第几个参数 (比如%1$f中的1代表第一个参数),f代表浮点数



When calling  TextView#setText:
  • Never call Number#toString() to format numbers; it will not handle fraction separators and locale-specific digits properly. Consider using String#format with proper format specifications (%d or %f) instead.
  • Do not pass a string literal (e.g. "Hello") to display text. Hardcoded text can not be properly translated to other languages. Consider using Android resource strings instead.
  • Do not build messages by concatenating text chunks. Such messages can not be properly translated.
    来源:  https://stackoverflow.com/questions/33164886/android-textview-do-not-concatenate-text-displayed-with-settext
【Android TextView : “Do not concatenate text displayed with setText”】 

来源:  http://www.bubuko.com/infodetail-1251094.html

来自为知笔记(Wiz)















    推荐阅读