gpt4 book ai didi

java - Java/Android 中的 Rss feed 布局

转载 作者:行者123 更新时间:2023-12-02 07:27:03 26 4
gpt4 key购买 nike

我想要在 Android 应用中显示 RSS Feed。基本上,它当然是从 XML 文件读取。我想在 Android listView 中显示两个项目:titledescription

我希望提要执行此操作:

title
description

title
description

title
description

title
description

相反,它正在这样做:

title
title
title
title
title
title

description
description
description
description
description
description

根据这段代码,我可以明白为什么,但我不知道如何像示例 1 那样布局。

这里是代码:

private class RSSHandler extends DefaultHandler {

public void startElement(String uri, String localName, String qName,
Attributes attrs) throws SAXException {

if (localName.equals("item")) {
item = true;
}

if (localName.equalsIgnoreCase("title")) {
fTitle = true;
}

if (localName.equalsIgnoreCase("description")) {
fDesc = true;
}

}

public void endElement(String namespaceURI, String localName,
String qName) throws SAXException {

}

public void characters(char[] ch, int start, int length)
throws SAXException {

if (fTitle) {
titleResult = titleResult + (new String(ch, start, length))
+ "\t\n\n";
fTitle = false;
}

if (fDesc) {
rssResult = rssResult + (new String(ch, start, length))
+ "\t\n\n";
fDesc = false;
}

}

}

最佳答案

您正在维护两个字符串并稍后将它们组合起来,您应该在构建它们时将它们组合起来。根据你的例子,你应该使用这样的东西:

public void characters(char[] ch, int start, int length)
throws SAXException {

if (fTitle) {
titleResult = titleResult + (new String(ch, start, length))
+ "\t\n";
fTitle = false;
}

if (fDesc) {
titleResult = titleResult + (new String(ch, start, length))
+ "\t\n\n";
fDesc = false;
}
}

关于java - Java/Android 中的 Rss feed 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13423009/

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