##Do not concatenate text displayed with setText 当使用下面的方法对TextView进行setText时html
prodNameView.setText("" + name); prodOriginalPriceView.setText("" + String.format(getString(R.string.string_product_rate_with_ruppe_sign), "" + new BigDecimal(price).setScale(2, RoundingMode.UP)));
会有以下提示android
Do not concatenate text displayed with setText. Use resource string with placeholders.git
When calling TextView#setText:ide
- 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.
简单来讲使用TextView的setText方法时,有三点要注意的:ui
##例子 在String资源文件中声名编码
<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>
在TextView中经过setText设置code
hello.setText(getString(R.string.welcome_messages,"John",10));
##参考 stackoverflow中的问题orm
Android官方文档htm