当前位置:网站首页>Do not concatenate text displayed with setText,use resource string with placeholders.

Do not concatenate text displayed with setText,use resource string with placeholders.

2022-06-10 11:47:00 yechaoa

General warning :

You should use resource strings to display text placeholders

And in xml The warning that Chinese characters are written directly in the layout means

String splicing is also good , Chinese characters written directly are also good ,

It should be in strings.xml Declaration in the document , Then the reference

for example:

layout.xml File reference

strings.xml Declaration in the document

About variable splicing parameters

such as :

mTextView.setText(" There is still... Before the Chinese New Year "+mDay+" God "+mMinute+" when "+mSecond+" second ");

Statement :

<string name="delay_time"> There is still... Before the Chinese New Year %1$d God %2$d when %3$d second </string>

Use in code :

mTextView.setText(String.format(getResources().getString(R.string.delay_time),mDay,mMinute,mSecond));

The statement goes ahead , Parameter after Common formats : %n$s--->n Indicates the current number of parameters ( such as %1$s Medium 1 Represents the first parameter ),s Representative string %n$d--->n Indicates the current number of parameters ( such as %1$d Medium 1 Represents the first parameter ),d For integers %n$f--->n Indicates the current number of parameters ( such as %1$f Medium 1 Represents the first parameter ),f For floating-point numbers

原网站

版权声明
本文为[yechaoa]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101133346610.html