3

I have a Recycle view that i want to iterate over and add a bullet point in front of each input String.

I have the following:

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)
    }

This prints the same int over and over again without the bullet point.

what is the best practice to format strings in kotlin?

1 Answer 1

9

You should learn how Android works first. R.string.skill returns the resource id of the string which is an Int To get the String, from resource, you have to use

context.getString(resId)

It also supports string formatting.

context.getString(R.string.skill, skill)

context can be anything that extends Context, i.e Activity, Fragment.

To format String in Kotlin, you use string interpolation.

val world = "World"
val helloWorld = "Hello $world"  // Hello World
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.