gpt4 book ai didi

java - 在 Android 的 Java 中从 Map 的 ArrayList 获取 map

转载 作者:行者123 更新时间:2023-12-01 23:42:18 25 4
gpt4 key购买 nike

我正在开发一个 Android 应用程序。我的应用程序解析 XML 远程文件,并将第一个标签的数据存储在 map 的 ArraList 中,将第二个标签的数据存储在另一个 map 的 ArrayList 中。我将在这里发布我的 XML:

<?xml version="1.0" encoding="UTF-8"?>
<Programs>
<Program programNumber="1" imgURL="http://www.photovideolife.com/userfiles/Placeholder%2001.jpg" description="Lorem ipsum dolor sit er elit">
<Episode pN="1" episodeNumber="1" transmissionName="Titolo" date="29 Giu 2013" time1="14:30" time2="" channel="IRIS" channelLogo="http://indiscrezioni.files.wordpress.com/2010/06/logo_iris.jpg">
</Episode>
<Episode pN="1" episodeNumber="1" transmissionName="Titolo" date="29 Giu 2013" time1="" time2="16:30" channel="La7" channelLogo="http://www.tabaccheriavenza.it/media/logo/la7.jpg">
</Episode>
<Episode pN="1" episodeNumber="2" transmissionName="Titolo" date="01 Lug 2013" time1="14:30" time2="" channel="IRIS" channelLogo="http://indiscrezioni.files.wordpress.com/2010/06/logo_iris.jpg">
</Episode>
<Episode pN="1" episodeNumber="2" transmissionName="Titolo" date="01 Lug 2013" time1="" time2="16:30" channel="la7" channelLogo="http://www.tabaccheriavenza.it/media/logo/la7.jpg">
</Episode>
</Program>
<Program programNumber="2" imgURL="http://mesa.umich.edu/files/mesa/field/image/placeholder2.png" description="Lorem ipsum dolor sit er elit">
<Episode pN="2" episodeNumber="1" transmissionName="Titolo 1" date="30 Giu 2013" time1="13:30" time2="" channel="Rai 1" channelLogo="http://i822.photobucket.com/albums/zz145/Mattelufregn/Loghi%20canali%20tv/70px-Logo_Rai_1_2010svg50x50.png">
</Episode>
<Episode pN="2" episodeNumber="1" transmissionName="Titolo 1" date="30 Giu 2013" time1="" time2="18:30" channel="Rai 5" channelLogo="http://www.tuttotv.info/wp-content/uploads/2011/04/logo_rai5_50.jpg">
</Episode>
<Episode pN="2" episodeNumber="2" transmissionName="Titolo 1" date="01 Lug 2013" time1="13:30" time2="" channel="Rai 1" channelLogo="http://i822.photobucket.com/albums/zz145/Mattelufregn/Loghi%20canali%20tv/70px-Logo_Rai_1_2010svg50x50.png">
</Episode>
<Episode pN="2" episodeNumber="2" transmissionName="Titolo 1" date="01 Lug 2013" time1="" time2="18:30" channel="Rai 5" channelLogo="http://www.tuttotv.info/wp-content/uploads/2011/04/logo_rai5_50.jpg">
</Episode>
</Program>
<Program programNumber="3" imgURL="http://wp.contempographicdesign.com/wp_paramount/wp-content/themes/paramount/images/image_placeholder_lrg.jpg" description="Lorem ipsum dolor sit er elit">
<Episode pN="3" episodeNumber="1" transmissionName="Titolo 2" date="30 Giu 2013" time1="10:30" time2="" channel="Canale 5" channelLogo="http://www.mozaic.qa/logo/canale5.jpg">
</Episode>
<Episode pN="3" episodeNumber="1" transmissionName="Titolo 2" date="30 Giu 2013" time1="" time2="17:30" channel="Italia 1" channelLogo="http://upload.wikimedia.org/wikipedia/it/thumb/3/30/Logo_Italia_1.svg/50px-Logo_Italia_1.svg.png">
</Episode>
<Episode pN="3" episodeNumber="2" transmissionName="Titolo 2" date="01 Lug 2013" time1="10:30" time2="" channel="Canale 5" channelLogo="http://www.mozaic.qa/logo/canale5.jpg">
</Episode>
<Episode pN="3" episodeNumber="2" transmissionName="Titolo 2" date="01 Lug 2013" time1="" time2="17:30" channel="Italia 1" channelLogo="http://upload.wikimedia.org/wikipedia/it/thumb/3/30/Logo_Italia_1.svg/50px-Logo_Italia_1.svg.png">
</Episode>
</Program>
</Programs>

在解析结束时,我有一个用于节目的 ArrayList 和一个用于剧集的 ArrayList。您可以看到 Programs 和 Episode 有一个公共(public)字段(programNumber 和 pN),现在我需要获取 Episode ArrayList 中存储的数据来获取正确的节目。我怎样才能做到这一点?我在网上找到了这个解决方案:

for (HashMap<String, String> programsMap : programs) {
for (Map.Entry<String, String> entry : programsMap.entrySet()) {
// I added some code here
}
}

我该如何解决这个问题?谢谢您的建议。

最佳答案

String programNumber = "3";
// create the result list (empty initially)
List<Map<String, String>> episodesForProgramNumber = new ArrayList<>();

// loop through all the episodes
for (Map<String, String> episode : allEpisodes) {

// if the current episode has the given program number, add it to the result
if (programNumber.equals(episode.get("pN")) {
episodesForProgramNumber.add(episode);
}
}

但是 Java 是一种面向对象的语言。您不应该使用 map 来存储数据。您应该使用 Program 类型的对象和Episode 。与Program包含List<Episode> .

关于java - 在 Android 的 Java 中从 Map 的 ArrayList 获取 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17721660/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com