Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8362963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:03:56+00:00 2026-06-09T12:03:56+00:00

I have a feed I’m parsing and wondering how to parse two lines of

  • 0

I have a feed I’m parsing and wondering how to parse two lines of information and an image. I can successfully parse one line of text but haven’t figured out how to pull image from it and second line of text i want. Here is a picture of what i want to accomplish

example of what i want to accomplish

here is the code for my parser

 public class XmlPullFeedParser extends BaseFeedParser {

public XmlPullFeedParser(String feedUrl) {
    super(feedUrl);
}

public List<Message> parse() {
    List<Message> messages = null;
    XmlPullParser parser = Xml.newPullParser();
    try {
        // auto-detect the encoding from the stream
        parser.setInput(this.getInputStream(), null);
        int eventType = parser.getEventType();
        Message currentMessage = null;
        boolean done = false;
        while (eventType != XmlPullParser.END_DOCUMENT && !done){
            String name = null;
            switch (eventType){
                case XmlPullParser.START_DOCUMENT:
                    messages = new ArrayList<Message>();
                    break;
                case XmlPullParser.START_TAG:
                    name = parser.getName();
                    if (name.equalsIgnoreCase(ITEM)){
                        currentMessage = new Message();
                    } else if (currentMessage != null){
                        if (name.equalsIgnoreCase(LINK)){
                            currentMessage.setLink(parser.nextText());
                        } else if (name.equalsIgnoreCase(DESCRIPTION)){
                            currentMessage.setDescription(parser.nextText());
                        } else if (name.equalsIgnoreCase(PUB_DATE)){
                            currentMessage.setDate(parser.nextText());
                        } else if (name.equalsIgnoreCase(TITLE)){
                            currentMessage.setTitle(parser.nextText());
                        }   
                    }
                    break;
                case XmlPullParser.END_TAG:
                    name = parser.getName();
                    if (name.equalsIgnoreCase(ITEM) && currentMessage != null){
                        messages.add(currentMessage);
                    } else if (name.equalsIgnoreCase(CHANNEL)){
                        done = true;
                    }
                    break;
            }
            eventType = parser.next();
        }
    } catch (Exception e) {
        Log.e("Trey's Blog::PullFeedParser", e.getMessage(), e);
        throw new RuntimeException(e);
    }
    return messages;
}
 }

my list activity

 public class MessageList extends ListActivity {

private List<Message> messages;

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.activity_main);
    loadFeed(ParserType.XML_PULL);
}


@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Intent viewMessage = new Intent(Intent.ACTION_VIEW, 
            Uri.parse(messages.get(position).getLink().toExternalForm()));
    this.startActivity(viewMessage);
}

private void loadFeed(ParserType type){
    try{
        Log.i("Trey's Blog", "ParserType="+type.name());
        FeedParser parser = FeedParserFactory.getParser(type);
        long start = System.currentTimeMillis();
        messages = parser.parse();
        long duration = System.currentTimeMillis() - start;
        Log.i("Trey's Blog", "Parser duration=" + duration);
        String xml = writeXml();
        Log.i("Trey's Blog", xml);
        List<String> titles = new ArrayList<String>(messages.size());
        for (Message msg : messages){
            titles.add(msg.getTitle());
        }
        ArrayAdapter<String> adapter = 
            new ArrayAdapter<String>(this, R.layout.row,titles);
        this.setListAdapter(adapter);
    } catch (Throwable t){
        Log.e("Trey's Blog",t.getMessage(),t);
    }
}

private String writeXml(){
    XmlSerializer serializer = Xml.newSerializer();
    StringWriter writer = new StringWriter();
    try {
        serializer.setOutput(writer);
        serializer.startDocument("UTF-8", true);
        serializer.startTag("", "messages");
        serializer.attribute("", "number", String.valueOf(messages.size()));
        for (Message msg: messages){
            serializer.startTag("", "message");
            serializer.attribute("", "date", msg.getDate());
            serializer.startTag("", "title");
            serializer.text(msg.getTitle());
            serializer.endTag("", "title");
            serializer.startTag("", "url");
            serializer.text(msg.getLink().toExternalForm());
            serializer.endTag("", "url");
            serializer.startTag("", "body");
            serializer.text(msg.getDescription());
            serializer.endTag("", "body");
            serializer.endTag("", "message");
        }
        serializer.endTag("", "messages");
        serializer.endDocument();
        return writer.toString();
    } catch (Exception e) {
        throw new RuntimeException(e);
    } 
}
 }

my feed parser

 public abstract class FeedParserFactory {
static String feedUrl = "http://treymorgan.net/feed";

public static FeedParser getParser(){
    return getParser(ParserType.ANDROID_SAX);
}

public static FeedParser getParser(ParserType type){
    switch (type){
        case SAX:
            return new SaxFeedParser(feedUrl);
        case DOM:
            return new DomFeedParser(feedUrl);
        case ANDROID_SAX:
            return new AndroidSaxFeedParser(feedUrl);
        case XML_PULL:
            return new XmlPullFeedParser(feedUrl);
        default: return null;
    }
}
 }

and message activity

 public class Message implements Comparable<Message>{
static SimpleDateFormat FORMATTER = 
    new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
private String title;
private URL link;
private String description;
private Date date;

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title.trim();
}
// getters and setters omitted for brevity 
public URL getLink() {
    return link;
}

public void setLink(String link) {
    try {
        this.link = new URL(link);
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
}

public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description.trim();
}

public String getDate() {
    return FORMATTER.format(this.date);
}

public void setDate(String date) {
    // pad the date if necessary
    while (!date.endsWith("00")){
        date += "0";
    }
    try {
        this.date = FORMATTER.parse(date.trim());
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
}

public Message copy(){
    Message copy = new Message();
    copy.title = title;
    copy.link = link;
    copy.description = description;
    copy.date = date;
    return copy;
}

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("Title: ");
    sb.append(title);
    sb.append('\n');
    sb.append("Date: ");
    sb.append(this.getDate());
    sb.append('\n');
    sb.append("Link: ");
    sb.append(link);
    sb.append('\n');
    sb.append("Description: ");
    sb.append(description);
    return sb.toString();
}

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((date == null) ? 0 : date.hashCode());
    result = prime * result
            + ((description == null) ? 0 : description.hashCode());
    result = prime * result + ((link == null) ? 0 : link.hashCode());
    result = prime * result + ((title == null) ? 0 : title.hashCode());
    return result;
}

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    Message other = (Message) obj;
    if (date == null) {
        if (other.date != null)
            return false;
    } else if (!date.equals(other.date))
        return false;
    if (description == null) {
        if (other.description != null)
            return false;
    } else if (!description.equals(other.description))
        return false;
    if (link == null) {
        if (other.link != null)
            return false;
    } else if (!link.equals(other.link))
        return false;
    if (title == null) {
        if (other.title != null)
            return false;
    } else if (!title.equals(other.title))
        return false;
    return true;
}

public int compareTo(Message another) {
    if (another == null) return 1;
    // sort descending, most recent first
    return another.date.compareTo(date);
}
 }

I have been researching this for a while and havn’t found anything that works on this. Any information anyone can give would be greatly appreciated. Pretty new to parsing so trying to learn this as i go. Thanks again.


Found a great Tutorial to help me achive the view i wanted to do and here is the link for it.

http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/

Hope this will help someone

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:03:57+00:00Added an answer on June 9, 2026 at 12:03 pm

    You’re using the ArrayAdapter this adapts an array of strings and shows one string on each list item.

    You’ll need to:

    • create a custom adapter
    • extend BaseAdapter
    • pass it a custom layout that represents one list item
    • pass it your List of Message‘s
    • in the getView() method retrieve one Message and set the title description and image

    This is your culprit code:

    ArrayAdapter<String> adapter =  new ArrayAdapter<String>(this, R.layout.row, titles);
    this.setListAdapter(adapter);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a feed with images in the description node. How can I parse
I have a feed that is populating a single text field in a table
I have a xml feed which needs to be converted to HTML. How can
I have a feed that lists news items, click on one and you get
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have one table with USERS and another table with RSS FEED URLS. Both
I have the following feed which I wish to parse and grab certain data
I am new to Android. I want to parse RSS feed. I have this
We have a feed process which runs every day of the year. As part
I have a feed table with say fields: id - unique feed id created

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.