敢说敢作敢为, 无怨无恨无悔。这篇文章主要讲述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
来源: http://www.bubuko.com/infodetail-1251094.html
来自为知笔记(Wiz)
推荐阅读
- apple Swift语言新手教程
- android 常见分辨率与DPI对照表
- Android如何改变TextView字体间距
- Android Studio中 ADB WIFI插件进行无线调试实践
- Android N 设置中语言列表介绍
- Android studio快捷键设置
- Android之——多线程下载演示样例
- ionic App 解决android端在真机上 tab处于顶部的Bug
- Mapper not initialized. Call Initialize with appropriate configuration.