I want an RSS Feed displayed in an Android app. Basically, it’s reading from an XML file of course. There are two items I want displayed in the Android listView: title, description.
I want the feed to do this:
title
description
title
description
title
description
title
description
instead it is doing this:
title
title
title
title
title
title
description
description
description
description
description
description
I can see why based on how this code is, but I can’t figure out how to layout like example number 1.
Here is code:
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;
}
}
}
You are maintaining two strings and combining them later, you should combine them as you build them. According to your example you should use something like this: