我有一个 html 格式的资源,因为我想这样显示它
<string name="calculator_bottom_sheet_body" translatable="false">
<![CDATA[<b>Basic requirements</b><br /><br />
You must be between 18 - 70 in order to proceed:
<ul>
<li> requirement 1</li>
<li> requirement 2</li>
<li> requirement 3 and</li>
<li> requirement 4</li>
</ul> <br /><br />
<b>Money requirement:</b><br /><br />
From €500 to €15.000<br /><br />
<b>Duration:</b><br /><br />
From 6 to 84 months<br /><br />
If you like to continue press the button below.]]>
</string>
从片段中我检索字符串
val body = resources.getString(R.string.calculator_bottom_sheet_body)
效果很好。 但是我想要 €500、€15.000 的值给像 €%s、€%s 这样的变量。所以在我转换线之后
From €%s to €%s<br /><br />
我需要从片段中调用资源,例如
val body = resources.getString(R.string.calculator_bottom_sheet_body, minAmount, maxAmount)
这就是我收到此错误的地方
Wrong argument count, format string calculator_bottom_sheet_body requires 1 but format call supplies 2
有人知道问题出在哪里吗??
我认为你需要更新你的字符串
From €%s to €%s<br /><br />
到
From €%1$s to €%2$s<br /><br />
并像这样使用它
val body = String.format(context.getResources().getString(R.string.calculator_bottom_sheet_body), minAmount, maxAmount)
希望这有帮助。