I want to make the app show me the string like "24 girls"; but when I use dataBinding , the space in string can't be shown,the string change like "24girls".
This is my code:
You can't use them togheter in the same layout. ViewBinding is a subset of what DataBinding can do and should be used if you want to replace libraries like ButterKnife , KotterKnife or KAE (Kotlin Android Extensions) but don't want to invest in databinding refactoring.
You just have to import <import type="android. content. Context" /> in your xml data imports. Then, you can access context for your databinding simply with context .
I would suggest you to use plurals for this.
In your strings.xml
add this:
<plurals name="scores">
<item quantity="one">%d Girl</item>
<item quantity="other">%d Girls</item>
</plurals>
and in your layout file
android:text="@{@plurals/scores(setScore.score, setScore.score)}"
The first setScore.score
is used to decide which string should be used from the plurals
.
And the second setScore.score
is for argument %d
we mentioned in plurals
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With