【发布时间】:2015-12-02 07:09:25
【问题描述】:
我创建了 2 个 xml 文件:
res/xml/comedy.xml
<comedy>
<item title="Grown Ups" length="90min"/>
<item title="Grown Ups 2" length="90min"/>
<item title="Scary Movie" length="90min"/>
<item title="Superbad" length="90min"/>
<item title="Zoolander" length="90min"/>
<item title="Groundhog Day" length="90min"/>
<item title="Beverly Hills Cop" length="90min"/>
<item title="Beverly Hills Cop II" length="90min"/>
<item title="Hangover" length="90min"/>
<item title="Anchorman" length="90min"/>
<item title="Pineapple Express" length="90min"/>
<item title="Happy Gilmore" length="90min"/>
<item title="We're the Millers" length="90min"/>
<item title="Horrible Bosses" length="90min"/>
<item title="Horrible Bosses 2" length="90min"/>
<item title="Meet the Parents" length="90min"/>
res/xml/action.xml
<action>
<item title="Man in Black" length="90min"/>
<item title="Man in Black II" length="90min"/>
<item title="Man in Black III" length="90min"/>
<item title="Mission: Impossible" length="90min"/>
<item title="Mission: Impossible II" length="90min"/>
<item title="Mission: Impossible - The Phantom Pain" length="90min"/>
<item title="Terminator" length="90min"/>
<item title="Die Hard" length="90min"/>
<item title="Back to the Future" length="90min"/>
<item title="The Bourne Identity" length="90min"/>
<item title="Marvel's The Avengers" length="90min"/>
<item title="Jurassic Park" length="90min"/>
<item title="Jurassic World" length="90min"/>
<item title="The Dark Night" length="90min"/>
<item title="The Matrix" length="90min"/>
<item title="Kill Bill - Volume 2" length="90min"/>
<item title="Apocalypto" length="90min"/>
<item title="Apocalypse Now" length="90min"/>
<item title="Aliens" length="90min"/>
现在我想从每个文件中随机抽取一部影片。
有没有办法可以直接做到这一点?还是我必须用XmlPullParser(如here)取出所有项目,然后使用随机生成器?
附注
1:我不完全确定我制作这些xml 文件的方式是否理想。我只是将自己定位在链接中的示例上。如果你有更好的想法,请告诉我。
2:最终目标是在用户选择一种或多种类型后在应用中显示随机电影。
【问题讨论】:
-
您需要将 xml 文件加载为某种数组,然后从中获取随机索引
-
谢谢丹尼尔。那是我的 B 计划。但在制作应用程序的后期,我想提取随机电影,不仅按类型过滤,还按长度过滤。当我使用数组时,比如here,我不能这样做。或者我可以吗?
-
如果我是你,我会使用 JSON。想看吗?
-
@ShifarShifz 你有什么特别的 API 吗?
-
noo.......