1

In fragments navigation codelabs I found a use of curly braces {} inside a string tag in string.xml

<string name="word_list_fragment_label">Words That Start With {letter}</string>

On running the app {letter} is replaced with whatever letter button user presses. What does {letter} refer to?

2 Answers 2

2

{x} gets replaced with a value x from navigation arguments.

This is a "new" feature of androidx-navigation 1.0.0 alpha 08:

Destination labels, when used with NavigationUI methods, will now automatically replace {argName} instances in your android:label with the correct argument b/80267266

Source: https://developer.android.com/jetpack/androidx/releases/navigation (page fragment names duplicated so cannot link directly to that release)

Android issue tracker: https://issuetracker.google.com/issues/80267266

1
  • interesting..i deleted my answer
    – sasikumar
    Sep 8, 2021 at 12:33
-2

Follow this steps:

step 1: add this string in your XML file

<string name="word_list_fragment_label">Words That Start With &#123; %s &#125;</string>

step 2: in your activity perform set text like this :

yourTextView.text = String.format(getString(R.string.word_list_fragment_label),"Your text that you want to set")
1
  • how does this answer the question ? Sep 8, 2021 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.