如何将整数值赋给strings.xml中的spinner项并在代码中读取它们?
我有些东西是这样的:
我显示的字符串
我需要的是为每个项目分配一个整数值,以便在我的活动中,而不是在选定的项索引中,我可以检索该值。
在我的strings.xml中有什么方法可以做到这一点,而不是用java编写代码呢?(有些东西类似于HTML中的内容)
这是我在布局xml中的旋转器:
发布于 2014-09-08 20:15:02
你可以用这样的东西
<resources>
<string-array name="app_modes">
<item tag="101">Beginner</item>
<item tag="102">Intermediate</item>
<item tag="103">Expert</item>
</string-array>
</resources>现在,在程序中,您可以在课程之外获得这些标记值,
int tagValue = Integer.parseInt(modeSpinner.getItemAtPosition(modeSpinner.getSelectedItemPosition()).getTag().toString()));或者用这种方法,
int tagValue = Integer.parseInt(modeSpinner.getSelectedItem().getTag().toString());希望这能解决你的问题,
https://stackoverflow.com/questions/24611679
复制相似问题