Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

android - Concatenate multiple strings in XML?

I go through this How to concatenate multiple strings in android XML? and in the end there are comments that

For clarity, Its works:

<string name="title">@string/app_name</string>.Andrzej Du?

I made my own example but it doesn't works. So does Andrzej wrong or I am doing something wrong in my code.

R.strings.bbb should contains "bbb aaa" but instead of "bbb aaa" it contains "bbb @strings/aaa"

<string name="aaa">aaa</string>
<string name="bbb">bbb @strings/aaa</string>

Query:

Is it possible to do some concatenation only in xml, without source code changes?

Reason why I don't want to edit in code because I use this strings in xml/preferences.xml

For Example:

<ListPreference android:key="key_bbb" android:title="@string/bbb" ....

If you know what I mean, here there is no possibility to use something like this

String title = res.getString(R.string.title, appName);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No, you can't concatenate strings in XML but you can define XML resources.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE resources [
  <!ENTITY appname "MyAppName">
  <!ENTITY author "MrGreen">
]>

<resources>
    <string name="app_name">&appname;</string>
    <string name="description">The &appname; app was created by &author;</string>
</resources>

The original answer was posted here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...