Reference one string from another string in strings.xml?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Reusing string resources in Android is useful when the same phrase appears in several places and should stay consistent across localization updates. The main point is to distinguish between resource references and formatted strings, because they solve different problems. In practice, formatted placeholders are usually safer than trying to build large strings by nesting resource references directly. That keeps both maintenance and translation quality under control.
The Difference Between Referencing and Formatting
In Android resources, @string/name is primarily a resource reference used by layouts and attributes. Inside string text itself, the usual reusable pattern is string formatting with placeholders.
Example base strings:
Then format in code:
This is clearer and more localization-friendly than trying to hardwire one resource into another resource body.
Direct Resource Reference in XML Attributes
Where @string/... shines is in XML attributes:
That is a direct resource lookup, not a string-to-string composition feature.
Why Formatting Usually Wins
Using placeholders has several advantages:
- translators can reorder phrases naturally
- shared pieces stay centralized
- runtime composition is explicit
For example:
In some languages, the brand name or noun order may need to move. Placeholders support that.
When Nested String Reuse Gets Messy
Trying to compose long sentences from many little resource fragments usually hurts localization quality. Translators need the whole sentence context, not scattered pieces that only make sense in English word order.
Good reuse:
- app name
- short labels
- product or feature names
Risky reuse:
- long legal sentences assembled from fragments
- grammar-sensitive phrases
- text with plural or gender variation
For those cases, create one complete translatable string instead.
HTML and Formatting Together
If you also need styling, keep the placeholder approach and format first, then parse if needed.
This keeps reuse and styling under control without duplicating brand names everywhere.
Plurals Need Separate Handling
If the reusable text includes counts, do not force normal string placeholders to do pluralization work. Use Android plural resources instead, then compose carefully in code where needed. Quantity rules differ across languages, so reuse should never undermine correct localization grammar.
Testing Localized Output
Whenever one string depends on another, test in at least one non-English locale. Reuse that feels tidy in English can become awkward in languages with different word order or inflection rules.
This is less about Android syntax and more about writing resource structures that survive translation.
Common Pitfalls
- Assuming
@string/...inside string text behaves like a general-purpose string macro system. - Building long UI sentences from small fragments and making localization awkward.
- Forgetting that placeholders are usually the cleaner reuse mechanism.
- Reusing strings with grammar that changes across languages.
- Testing only English and missing broken phrasing in other locales.
Summary
- Use
@string/...directly in XML attributes to reference resources. - Use string placeholders and
getStringformatting when one string depends on another. - Prefer full translatable sentences over fragment assembly for localization-heavy text.
- Reuse short stable pieces such as app names and labels carefully.
- Validate reused strings in real localized output, not only in English.
Related reading
- Referencing a string in a string array resource with xml
- Refresh certain row of UITableView based on Int in Swift
- Refresh devices in team provisioning profile managed by Xcode 7?
- Refreshing OAuth token using Retrofit without modifying all calls
- Refreshing UITableView Asynchronously after Core Data Loaded Swift
- Register Application class in Manifest?
- Registering for Push Notifications in Xcode 8/Swift 3.0?
- Reload activity in Android
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.