32

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!

Cheryl Simon
  • 45,901
  • 15
  • 92
  • 82

2 Answers2

27

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.

CommonsWare
  • 954,112
  • 185
  • 2,315
  • 2,367
-6

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

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

hxc
  • 860
  • 3
  • 13
  • 26
  • 3
    Please read the question. OP didnt want to set it in JAVA but in the layout file. – tobias Jan 05 '12 at 20:49
  • check http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling – hxc Jan 06 '12 at 03:03