Concatenate multiple strings in XML?
No I don't think you can concatenate.
<string name="aaa">aaa</string>
<string name="bbb">bbb @string/aaa</string>
Output - bbb @string/aaa
If you do,
<string name="aaa">aaa</string>
<string name="bbb">@string/aaa bbb</string> -> This won't work it
will give compilation error
Because here it will search for a String with reference @string/aaa bbb
which does not exists.
Problem in your case was, you where using @strings/aaa
which should be @string/aaa
I want to concat two strings for a TextView in android, Data Binding Api
concate it with grave accent (`)
android:text="@{`Hello ` + user.firstName}"/>
You can concat it in multiple ways, check it here concat-two-strings-in-textview-using-databinding
Concatenate Strings in the strings.xml file for Android
I am afraid that is not possible in strings.xml
.
What you can do is create the final string programmatically using getString
:
String outStr = getString(R.string.your_android_says) +
" " + getString(R.string.hello);
Concatenation in XML
You must take reference to your TextView, then you can do something like this:
textView.setText(textView.getText().toString() + letter);
How can I concatenate static strings with XML string resources?
Sorry, no such syntax is supported by Android resource files.
Concatenate string and integer in string.xml
You can not concatenate strings or integer and strings in xml. You can do refer to another string or integer in one string or integer tag respectively in xml , but only one.
Like:
<integer name="min_length">10</integer>
<integer name="min">@integer/min_length</integer>
You can refer integer inside integer and string inside string .
If you try to do what you mentioned above android studio , you will be thrown away with error.
how to concat two string resource in xml textview without binding
What you want is possible to be done statically.
But, a little search gave me this library LikeTheSalad
Extract of the README :
It allows you to do something like this:
<string name="app_name">world</string>
<string name="template_welcome_message">hello ${app_name}</string>
And then the library does this at build time:
<string name="welcome_message">hello world</string>
Related Topics
I Get Fragment Not Attached to a Context. What Context Need to Use
App Restarts Rather Than Resumes
How to Make a Link Open an Instagram Page in an App Installed on Android
How to Set Onclicklistener on Recyclerview Item in a Fragment
Refresh/Reload/Re Instantiate a Fragment in an Android Tab System
How to Customize Chart Labels for Mpandroidchart Library
Android Studio - Failed to Apply Plugin [Id 'Com.Android.Application']
Programmatically Retrieve Imei Number for Dual Sim in Android
How to Set the Height of an Item Row in Gridlayoutmanager
Send Text to Specific Contact Programmatically (Whatsapp)
Android How to Get Current Positon on Recyclerview That User Scrolled to Item
How to Disable All User Inputs (Click, Touch) on an Android View
Could Not Resolve All Dependencies for Configuration ':Classpath'
How to Stop Activity Resizing/Pushing Up on Keyboard Open in Dialog
Send Post Request With Json Data Using Volley
How to Save an Activity State Using the Save Instance State
How to Handle Notification When App in Background in Firebase