我有一个循环视图,我想迭代并在每个输入字符串前面添加一个项目点。
我有以下几点:
value.strings.xml
<string name="skill">• %1$s</string>ProfileListAdapter:
fun bindSkills(skill: String) {
itemView.recycleSkillItem.text = String.format(Locale(R.string.skill.toString()), ${R.string.skill}, skill)
}这会一次又一次地打印相同的int,而不带子弹点。
在kotlin中格式化字符串的最佳实践是什么?
发布于 2017-10-09 09:48:51
您应该首先了解Android是如何工作的。R.string.skill返回字符串的资源id,这是一个Int来获取字符串,从资源中,您必须使用
context.getString(resId)它还支持字符串格式设置。
context.getString(R.string.skill, skill)context可以是扩展Context的任何东西,即Activity、Fragment。
若要在Kotlin中格式化String,请使用字符串内插。
val world = "World"
val helloWorld = "Hello $world" // Hello Worldhttps://stackoverflow.com/questions/46642811
复制相似问题