gpt4 book ai didi

Java(安卓): Data in the string pattern

转载 作者:行者123 更新时间:2023-12-02 05:09:43 24 4
gpt4 key购买 nike

我有一个带有字符串的 TextView,我需要在其中插入数据。
类似于:“一些文本 %d 其他文本”。
我不想在我的源代码中包含硬编码文本。
有什么好的做法吗?

最佳答案

在您的 Activity 中,

String param1="something",param2="important";
int param3=233;

textView.setText(getResources().getText(R.string.tmpl, param1, param2,param3));

在你的 strings.xml 中

<string name="tmpl">here is %1$s %2$s which worth %3$d</string>

关于Java(安卓): Data in the string pattern,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27436802/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com