Settext notes of Textview (How to Use)

##Do not concatenate text displayed with settext

prodNameView.setText("" + name);  
prodOriginalPriceView.setText("" + String.format(getString(R.string.string_product_rate_with_ruppe_sign), "" + new BigDecimal(price).setScale(2, RoundingMode.UP)));

How do you suggest

Do not concatenate text displayed with setText. Do not concatenate text displayed with setText. Use resource string with placeholders.

When calling TextView#setText:

Never call Number#toString() to format numbers; locale-specific digits properly. 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. Do not build messages by concatenating text chunks. Such messages can not be properly translated.

Simply put, there are three things to keep in mind when using the setText method of a TextView.

If a number, use String#formatto modify

Special compilation, but use Android String36164; source file

Character set using+progress

##example in String36164;

<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>

Setting in textview by settext

hello.setText(getString(R.string.welcome_messages,"John",10));

##Refer to the problems in stackoverflow

Android official document

Similar Posts: