Android TextView: "Do not concatenate text displayed with SetText"

Source: Internet
Author: User

Reference: Http://stackoverflow.com/questions/33164886/android-textview-do-not-concatenate-text-displayed-with-settext

When TextView is dynamically updated to display data in activity, use:


Rgb_textview.settext (Settingdata.image_r + "," + Settingdata.image_g + "," + settingdata.image_b);

 

Then Android Studio will prompt: "Do not concatenate text displayed with Settext,use resource string with placeholders",

should read:

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>

It works fine without modification, but it's more canonical to modify it.


Common formats:
%n$s--->n that is currently the number of parameters (for example, 1 of%1 $ s represents the first parameter), s for the string
%n$d--->n that is currently the number of parameters (for example, 1 in%1$d for the first parameter), and D for an integer
%n$f--->n that is currently the number of parameters (such as 1 in%1$f for the first parameter), and F for floating-point numbers


When calling Textview#settext:

  • Never call number#tostring () to format numbers; It would not handle fraction separators and locale-specific digits properly. Consider using String#format with proper format specifications (%d or%f) instead.
  • does not pass a string literal (e.g. "Hello") to display text. hardcoded text can is 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.
  • Source: Https://stackoverflow.com/questions/33164886/android-textview-do-not-concatenate-text-displayed-with-settext
Source: http://www.bubuko.com/infodetail-1251094.html
From for notes (Wiz)


Android TextView: "Do not concatenate text displayed with SetText"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.