%d表示的是数字,%s表示的是字符串,当然还有很多别的格式。
在values里面的string.xml里面应该这样写:
<
string
name
="newslistpageshow"
><
xliff:g
>
%d
</
xliff:g
>
/
<
xliff:g
>
%d
</
xliff:g
></
string
>
当然前提是要在<resources>里面加入前缀:
<
resources
xmlns:xliff
="urn:oasis:names:tc:xliff:document:1.2"
>
然后在代码里面设置这两个值就可以了:
showPage.setText(
this
.getString(R.string.newslistpageshow, 1
, 2));
当然后面还可以加很多,比方说string.xml文件中有多少个<xliff:g>%d</xliff:g>
代码里面后面就应该给这几个都设上值。
API里面是这样说的:
final
String getString(
int
resId, Object... formatArgs)
Return a localized formatted string from the application ' s package ' s default string table, substituting the format arguments as defined in Formatter and format(String, Object...).
Return a localized formatted string from the application ' s package ' s default string table, substituting the format arguments as defined in Formatter and format(String, Object...).
这种TextView可以用于显示页号。