连接这些XML中的多个字符串? [英] Concatenate multiple strings in XML?

查看:451
本文介绍了连接这些XML中的多个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过这个<一个href="http://stackoverflow.com/questions/5764548/how-to-concatenate-multiple-strings-in-android-xml">How来连接多个字符串在Android的XML?,并在最后有评论认为

为了清楚起见,其作品:

&LT;字符串名称=称号&GT; @字符串/ APP_NAME&LT; /串&GT; - 安杰DUS

我做我自己的例子,但它不工作。所以做的安杰的错误还是我做错了什么在我的code。

R.strings.bbb 应包含BBB AAA 但代替BBB AAA包含BBB @字符串/ AAA

 &LT;字符串名称=AAA&GT; AAA&LT; /串&GT;
&LT;字符串名称=BBB&GT; BBB @字符串/ AAA&LT; /串&GT;
 

查询:

是否有可能做一些串联仅在XML中,没有源$ C ​​$ C的变化?

我之所以不想在code编辑,因为我用这个字符串 XML / preferences.xml

例如:

&LT;表preference安卓键=key_bbb机器人:标题=@字符串/ BBB ...

如果你明白我的意思,这里有没有可能使用这样的事情

 字符串标题= res.getString(R.string.title,的appName);
 

解决方案

不,我不认为你可以连接。

 &LT;字符串名称=AAA&GT; AAA&LT; /串&GT;
&LT;字符串名称=BBB&GT; BBB @字符串/ AAA&LT; /串&GT;
 

输出 - BBB @字符串/ AAA

如果你做的,

 &LT;字符串名称=AAA&GT; AAA&LT; /串&GT;
&LT;字符串名称=BBB&GT; @字符串/ AAA BBB&LT; /串&GT; - &GT;这将不能工作,
                                                      会给编译错误
 

由于这将搜索与引用的String @字符串/ AAA BBB 不存在。

在你的情况的问题是,你在哪里使用 @字符串/ AAA @字符串/ AAA

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);

解决方案

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

这篇关于连接这些XML中的多个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆