2014-02-07 90 views
1
的一系列圖像

我試圖找到yout,從此鏈接顯示一組圖像的方式是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; 
} 
} 

回答

2

試試這個代碼:在這個方法中

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

添加以下代碼將從元素返回的網址:

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

飼料我回

+0

關於如何展示他們?我必須添加 _final int state_enclosure_和_public vois chatacter()_方法添加此: _case state_enclosure: item.setEnclosure(strCharacters); break; _; case state_title: feed.setTitle(strCharacters); 休息; – Pier

+0

如果你只需要你不需要的URL實現chatacter(),你會從startElement方法 中的url中獲得值,你需要將它保存在數組中,解析後下載它們,你可以在你的視圖中顯示它們,你用state_enclosure表示什麼? –

+0

沒什麼,我很困惑。那麼爲了在我的ArrayAdapter中展示它們,這代碼很好嗎? – Pier