PTT
Submit
Submit
选择语言
正體中文
简体中文
PTT
AndroidDev
[问题] 字串填入问题
楼主:
lihohsin
(新)
2017-03-23 15:15:04
请问大家这段程式码
String strSug = getString(R.string.result);
if (msSex.equals(getString(R.string.sex_male)))
if (iAge < 28)
strSug += getString(R.string.sug_not_hurry);
else if (iAge > 33)
strSug += getString(R.string.sug_get_married);
else
strSug += getString(R.string.sug_find_couple);
else
if (iAge < 25)
strSug += getString(R.string.sug_not_hurry);
else if (iAge > 30)
strSug += getString(R.string.sug_get_married);
else
strSug += getString(R.string.sug_find_couple);
mTxtR.setText(strSug);
其中strSug += getString(R.string.sug_not_hurry);
这个+=在java中不是等于 strSug=strSug+getString(R.string.sug_not_hurry);
这样子在Android 怎么会是在StrSug中填入R.string.....中的资料呢?
作者:
pttworld
(批踢踢世界)
2017-03-23 15:21:00
literal资源管理,简单说写死。
楼主:
lihohsin
(新)
2017-03-23 15:46:00
就是在Android固定是这样写 对吗
作者:
ssccg
(23)
2017-03-23 15:59:00
看不懂你问题在哪里...getString就是取resource id对应的string假设 getString(R.string.sug_not_hurry) 取到的是 abc那就相当于 strSug = strSug + "abc";因为最上面有个strSug = getString(R.string.result)最后结果是result对应的string加上后面符合条件的string
作者:
LPH66
(-6.2598534e+18f)
2017-03-23 17:55:00
这段作用是把三个字串接起来, 你不 += 前面的字串就不见了啊, 不是三个字串, 是第一行和下面六种其一加起来例如说 result 是 "结果:" not_hurry 是 "还不急"第一行把 "结果:" 指定进去, 下面用 += 把 "还不急" 接上最后出来才会是 "结果:还不急"不用 += 直接 = 的话 "结果:" 就会不见了如果还是搞不太懂的话, 就实际改下去然后看看结果就知道了
继续阅读
[问题] Andriod连数据库
k732
[问题] 闪退
GooLoo
volley delete
lonelytea
[问题] App完成后执行闪退
UnReal5566
[问题] android 如何使用jwt加密?
gene07
[问题] SharedPreferences删除值的问题
Dong0129
Re: [问题] Android 7.0 https无法连线的问题
joycece
Re: [问题] Android 7.0 https无法连线的问题
benedict76
Re: [问题] Android 7.0 https无法连线的问题
joycece
[分享] Constraint Layout 奉上热腾腾笔记
romantic1027
Links
booklink
Contact Us: admin [ a t ] ucptt.com