File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Android and the fly likes How to parse short text data from a downloaded file in android? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "How to parse short text data from a downloaded file in android?" Watch "How to parse short text data from a downloaded file in android?" New topic
Author

How to parse short text data from a downloaded file in android?

Matt Ankner
Greenhorn

Joined: May 30, 2011
Posts: 5

I'm struggling to figure out how to do this the best way and need some help out. I'm making an app that has a calender type view (made of 12 buttons, one for each month) inside the main activity. The user is then able to click any of the twelve months which then opens up a new activity for each month.

My goal is to be able to pull from the internet a simple file (either text or xml preferably) that just has three things in, The movie name, date and format. From this downloaded file it will then populate my three line list-view. My question is and has been for several days, how do I get these three simple text items into each month via an external url download? I've included some code snippets below. Hopefully they'll help.




**The string class for each result**

public class SearchResults {
private String Name = "";
private String Date = "";
private String Format = "";

public String getName() {
return Name;
}
public void setName(String Name) {
this.Name = Name;
}
public String getDate() {
return Date;
}
public void setDate(String Date) {
this.Date = Date;
}
public String getFormat() {
return Format;
}
public void setFormat(String Format) {
this.Format = Format;
}


**This below is where the actual list-view is populated and shown. Each new search result creates a three line text-view inside each Month Activity**

private ArrayList<SearchResults> GetSearchResults(){
ArrayList<SearchResults> results = new ArrayList<SearchResults>();

SearchResults sr1 = new SearchResults();
sr1.setName("Movie #1");
sr1.setDate("July 24th");
sr1.setFormat("DVD, Blu-Ray");
results.add(sr1);

sr1 = new SearchResults();
sr1.setName("Movie #2");
sr1.seDate("July 19th");
sr1.setFormat("DVD, Blu-Ray, Digital");
results.add(sr1);


return results;
}
Hardik Trivedi
Ranch Hand

Joined: Jan 30, 2010
Posts: 252
Dude your question is not clear.Can you elaborate more?

I think you have a url which gives response in XML. You want that xml data in your app right ?
Well if this is the case you can use SAX parser or any convineient xml parser. It will give you the data in String format. Then you can use it in your app. You can make an adapter and can show in listview too
Matt Ankner
Greenhorn

Joined: May 30, 2011
Posts: 5

Sorry for being so vague. That was not my intention. School and work apparently don't mix well for allowing me put my thought online before proof reading it. Anyway, what you said is correct. I just want to be able to upload a file to my server space, whether it's xml or just a plain text file so that when a user opens my app it will refresh the list view within each activity with just three things. A movie name, it's retail release date and what format it will be releasing on and that's it.

For whatever reason whether it be due to my inexperience with java or something else, I cant seem to find the answer and I've been looking now for almost a week. Stack overflow I found out really quick is probably the least helpful source for novice information I could have ever come across which was both frustrating and disheartening to say the least.

I have everything in place and I'm able to update my list manually but I need to be able to push out new release updates since they come and go so quickly it would be silly to release an app update every other day or more.

I hope this helps you as well as any other takers that might be able to help me out. I'm coding this app for a friend and it's completed aside from this one last hiccup of the offsite release updates. I really appreciate your response by the way too.
Matt Ankner
Greenhorn

Joined: May 30, 2011
Posts: 5

Can anybody help me out with this? I'm at a stand still until I can figure this out.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5845
    
    7

I'm still not clear on what you are having a problem with. Is it:

a) You don't know how to get the file from the server to the phone.
b) You don't know how to tell when the file on the server has been updated so that it needs to be reloaded into the phone.
c) Once the file is on the phone, you don't know how to read it. (By the way, what format is the data it? XML? Or some text-style encoding (e.g, csv or line per datum)?
d) Once the file is on the phone you don't know how to get the code to recognize that there is an updated file which has to be re-read.
e) Your code notices the updated file and can read it just fine, but you can't seem to get the screen refreshed:
e-1) someone already clicked on a month button and they see some movie info, but that info doesn't get updated when new data is available
e-2) somebody clicks on a month button, but they never see anything (you can't get the data into the display fields)

It would also help if you showed up the layout file for the movie details screen and the code for that activity. (The code you have shown appears to populate an internal data structure, which isn't very helpful as far as displaying stuff goes.) Also, are you using a list activity with a list adapter?


JBoss In Action
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to parse short text data from a downloaded file in android?