【发布时间】:2020-06-29 23:21:39
【问题描述】:
我需要创建一个Spinner(或公开的下拉菜单),用户可以在其中选择持续时间,在本例中为天数。类似的东西
one day
two days
three days
稍后我想翻译这个应用程序,所以我不能在我的代码中使用显示的文本,例如像
if(item.equals("one day"))
对于英语以外的其他语言将失败。
所以我想要一个“显示值”(向用户显示的内容,例如“一天”)和一个技术 ID/密钥,例如“1DAY”。 Android 资源文件如何做到这一点?
我终于想要这样的东西了:
<!-- give a technical key 1DAY/2DAYS/3DAYS etc to the items -->
<!-- this is just a mockup - how could something like this be really done? -->
<string-array name="duration">
<item key="1DAY">@string/one_day</item>
<item key="2DAYS">@string/two_days</item>
<item key="3DAYS">@string/three_days</item>
<!-- and so on -->
</string-array>
<!-- these strings could be translated -->
<string name="one_day">one day</string>
<string name="two_days">two days</string>
<string name="three_days">three days</string>
【问题讨论】:
标签: android arrays resources spinner translation