Skip to content

Android coding session 2

February 3, 2011

After getting the London 2012 rss feed working, I thought it would be relatively simple to get the handball.xml feed working.

The first thing was that the xml feed had a different structure, that was ok as I had an idea of what to change in the code
I added the following into BaseFeedParser.java and
static final String MATCHDATE = "matchDate";

into androidSaxFeedParser.java
static final String SCORES = "scores";
RootElement root = new RootElement(SCORES);
Element channel = root.getChild(CHANNEL);
Element item = channel.getChild(ITEM);
item.getChild(MATCHDATE).setEndTextElementListener(new EndTextElementListener(){
public void end(String body) {
currentMessage.setTitle(body);
Log.d(TAG2, "matchdate " + body);

}
});

To match the rss xml structure, I also needed to add an element into the handball.xml, this made the structure easier to work with.
But I couldn’t get this to work, later I found out there was nothing wrong with this code, it was something else. So, I added logging functionality in order to help debug the code.
private static final String TAG2 = "param";
Log.d(TAG2, "matchdate " + body);

I created a local handball.xml file and added it to feedURL, but this file wouldn’t load. So I added the file to my local webserver (running MAMP) then updated feedURL to http://localhost:8888/handball.xml. The app still couldn’t access the file, finally after about 4 hours, I moved the file to an external webserver and it finally loaded, I found this very frustrating.

I then slowly added values and data to handball.xml, this worked and was successfully displayed in the emulator.
I also managed to output other values for example date, by adding this code into
messageList.java
titles.add(msg.getDate());


I still need to change the layout, as I want the content to be displayed in a table.

After a frustrating day, I finally manage to get it working, but I do understand the code and logging better, due to trying to debug.

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: