0

我正在尝试在我的 strings.xml 中引用格式化的字符串。我在谷歌上搜索,发现了这篇好文章:http: //developer.android.com/guide/topics/resources/string-resource.html

我遵循了它看起来的每一个细节,但打印出来的文本并不是它应该的样子。

首先,在我的资源下的strings.xml中,我将其定义为:

<string name="print_binary">This is the printout: %1$s</string>

在 .java 我放:

String fromString = "one";
Resources res = getResources();

onScreen = String.format(res.getString(R.string.print_binary), fromString);

这会在屏幕上显示以下文本:这是打印输出:%1$s

请指教

4

2 回答 2

0

您可以使用:

onScreen = res.getString(R.string.print_binary, fromString);

于 2012-08-04T20:29:27.987 回答
0

天哪,我完全错过了输入类似的东西

TextView show = (TextView) findViewById(R.id.tvDisplay); 
show.setText(onScreen); 

然后为我的 TextView 对象添加一个 id。晚上太晚了。似乎不需要 String.format() 语句,我会继续阅读。谢谢你的支持!

于 2012-10-21T19:26:42.443 回答