Issue
in strings.xml
I have one resource.
<string name="generic_price_with_rupee_symbol">\u20B9 %s</string>
This is what I do in Android data binding that works perfectly
<TextView
...
android:text="@{@string/generic_price_with_rupee_symbol(item.price)}"
/>
Question:
How to use this resource in java code? As I don't want to make new resource.
I tried
textView.setText(getString(R.string.generic_price_with_rupee_symbol) + "100");
That gives wrong result and prints %s
also.
Solution
It should be written like this -
textView.setText(getString(R.string.generic_price_with_rupee_symbol, "100"));
Check out String getString (int resId, Object... formatArgs) from Documentation.
Answered By - Paresh P.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.