Using String resource placeholders with data binding

Sven Bendel
Apr 27, 2018

--

Today I stumbled about one of these tiny things which — once you uncover them — immensely ease your life.

Consider a String with placeholders stored in your strings.xml:

Now let's say we want to use that String directly in data binding. Before figuring out the following trick I would fetch the data from the attached ViewModel which would use String.format() to replace the placeholder with e.g. the user name.

Turns out there is a by far easier way to do this directly within the layout:

Isn't that neat?

--

--

Sven Bendel

Senior Android Engineer @Photoroom. Founder. Crowdfunding addict. Trying hard to do the right thing and failing more often than not. https://proven.lol/286e9b