2014-02-07 5 views
1

나는이 링크 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 :URL에서 이미지 시퀀스 가져 오기 및 표시

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

피드 : 요소에서 URL을 반환이 코드를 추가하려면이 방법

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

:

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

이 코드를 시도 나 다시

+0

그리고 어떻게 보여줄 수 있습니까? _final int state_enclosure_ 및 _public vois chatacter() _ 메서드에 다음을 추가해야합니까 : _case state_enclosure : item.setEnclosure (strCharacters); 휴식; _; 사례 state_title : feed.setTitle (strCharacters); 휴식; – Pier

+0

chatacter()을 구현할 필요가없는 URL 만 필요하면 startElement 메소드 에서 url의 값을 얻을 수 있습니다. 배열로 저장해야하며, 파싱 한 후 다운로드하여 뷰에 표시 할 수 있습니다. state_enclosure로 무엇을 의미합니까 ?? –

+0

아무것도, 혼란 스러웠습니다. 그렇다면 ArrayAdapter에이 코드를 표시하는 것이 좋습니다. – Pier

관련 문제