首页 > 代码库 > 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
来源: http://www.bubuko.com/infodetail-1251094.html
来自为知笔记(Wiz)
Android TextView : “Do not concatenate text displayed with setText”
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。