从URL获取并显示一系列图像

时间:2014-02-07 21:37:16

标签: java android image url rss

我试图找到从这个链接www.repubblica.it/rss/tecnologia/rss2.0.xml显示一组图像的方法。我必须在我的RSS应用程序中显示它们,但我坚持这个论点。 图像位于此标记<enclosure url="http://www.repstatic.it/content/nazionale/img/2014/02/06/201914230-3e1f0f4a-c5e4-413a-acd0-f15b781438eb.jpg" length="24317" type="image/jpeg"/>中(例如)。 你能帮助我吗?任何帮助表示赞赏。 这是我的Handler

public class RSSHandler extends DefaultHandler {

 final int state_unknown = 0;
 final int state_title = 1;
 final int state_description = 2;
 final int state_link = 3;
 final int state_pubdate = 4;
 int currentState = state_unknown;

 RSSFeed feed;
 RSSItem item;

 boolean itemFound = false;

 RSSHandler(){
 }

 RSSFeed getFeed(){
 return feed;
 }

 @Override
 public void startDocument() throws SAXException {
 // TODO Auto-generated method stub
 feed = new RSSFeed();
 item = new RSSItem();

 }

 @Override
 public void endDocument() throws SAXException {
 // TODO Auto-generated method stub
 }

 @Override
 public void startElement(String uri, String localName, String qName,
 Attributes attributes) throws SAXException {
 // TODO Auto-generated method stub

 if (localName.equalsIgnoreCase("item")){
 itemFound = true;
 item = new RSSItem();
 currentState = state_unknown;
 }
 else if (localName.equalsIgnoreCase("title")){
 currentState = state_title;
 }
 else if (localName.equalsIgnoreCase("psi")){
 currentState = state_description;
 }
 else if (localName.equalsIgnoreCase("link")){
 currentState = state_link;
 }
 else if (localName.equalsIgnoreCase("pubdate")){
 currentState = state_pubdate;
 }
 else{
 currentState = state_unknown;
 }

 }

 @Override
 public void endElement(String uri, String localName, String qName)
 throws SAXException {
 // TODO Auto-generated method stub
 if (localName.equalsIgnoreCase("item")){
 feed.addItem(item);
 }
 }

  @Override
  public void characters(char[] ch, int start, int length)
  throws SAXException {
  // TODO Auto-generated method stub

  String strCharacters = new String(ch,start,length);

  if (itemFound==true){
  // "item" tag found, it's item's parameter
  switch(currentState){
  case state_title:
  item.setTitle(strCharacters);
  break;
 case state_description:
 item.setDescription(strCharacters);
 break;
 case state_link:
 item.setLink(strCharacters);
 break;
 case state_pubdate:
 item.setPubdate(strCharacters);
 break;
 default:
 break;
 }
 }
 else{
 // not "item" tag found, it's feed's parameter
 switch(currentState){
 case state_title:
 feed.setTitle(strCharacters);
 break;
 case state_description:
 feed.setDescription(strCharacters);
 break;
 case state_link:
 feed.setLink(strCharacters);
 break;
 case state_pubdate:
 feed.setPubdate(strCharacters);
 break;
 default:
  break;
 }
 }

  currentState = state_unknown;
 }
 }

1 个答案:

答案 0 :(得分:2)

试试这段代码:

在这个方法中

public void startElement(String uri, String localName, String qName,Attributes attributes)

添加此代码将返回元素中的url:

if ("enclosure".equals(qName)) {
        for (int i = 0; i < attributes.getLength(); i++)
            if (attributes.getQName(i).equals("url"))
                String url = attributes.getValue(i);

喂我回来