35

I have a string defined in my String.xml file that uses format arguments, i.e.:

<string name="myString">Hello %1$s.</string>

Is there a way to assign a value to the format argument in a layout xml file? I have something like:

<TextView android:text="@string/myString"/>

I know I can do it in java, but is there a way to do it here?

Thanks!

0

2 Answers 2

28

No, there is no means of applying a value to the format from a layout file -- only in Java. Sorry!

UPDATE: You can now use data binding for this — see the duplicate question.

Sign up to request clarification or add additional context in comments.

7 Comments

I kinda thought that might be the case, but I was hoping otherwise. Thanks!
7+ years later, is this answer still correct?
@GaryS.: You should be able to pull this off using the data binding framework.
Per what I studied, data binding expressions requires data so pure resources and operators does not work may data-binding is still not a very good solution.
It is possible now. See stackoverflow.com/a/38984088/3190931.
|
-6

For Example In strings.xml
You have %d unread messages

In Your Java code
String message = getString(R.string.unread_messages, 10);

2 Comments

Please read the question. OP didnt want to set it in JAVA but in the layout file.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.