2011-11-26 3 views
0

RSS 피드에서 참조하는 파일을 다운로드하여 arraylist와 작업하고 있습니다. 지금까지는 디스크에 저장되지 않았다고 생각합니다.android, 리소스 식별자를 메모리에서 bitmap/drawable로 가져 오는 방법은 무엇입니까?

  1. 디스크에 저장하지 않으면 사실 리소스 식별자가 있습니까?
  2. 그렇다면 어떻게 검색합니까?

의무 샘플 코드 : 사전에

URL url = new URL("http://someurl.com/rss"); 
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 
      DocumentBuilder db = dbf.newDocumentBuilder(); 
      Document doc = db.parse(new InputSource(url.openStream())); 
      NodeList postList = doc.getElementsByTagName("item"); 
      thumbIds = new Integer[postList.getLength()]; 
      for (int i = 0; i < postList.getLength(); i++) { 
       // extract post 
       Node post = postList.item(i); 
       Element postElement = (Element) post; 
       NodeList titleList = postElement.getElementsByTagName("media:thumbnail"); 
       Element titleElement = (Element) titleList.item(0); 
       String myUrl = titleElement.getAttribute("url").toString(); 
       if(myUrl != null) { 

        thumbs.add(new BitmapDrawable(fetchBitmap(myUrl))); 
       } 
      } 
public static Bitmap fetchBitmap(String url) { 

     URL newurl = null; 
     try { 
      newurl = new URL(url); 
     } catch (MalformedURLException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     Bitmap returnBitmap = null; 
     try { 
      returnBitmap = BitmapFactory.decodeStream(newurl.openConnection() 
        .getInputStream()); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     return returnBitmap; 
    } 

감사합니다!

+0

"디스크에 저장하지 않으면 사실 리소스 식별자가 있습니까?" - 아니, 그렇지 않을거야. "만약 그렇다면, 어떻게 되 찾을 수 있겠습니까?" - 무엇에서 무엇을 얻으려고? – CommonsWare

답변

2

저는 대답이 '아니오'인 것을 두려워합니다.

/res 폴더에 선언 된 파일에 대한 리소스 식별자 만 제공됩니다. 비트 맵을 응용 프로그램에 다운로드하여 저장하려는 경우 현재 내가 생각할 수있는 유일한 솔루션은 파일 (캐시 또는 외부) 또는 데이터베이스로 저장하는 것입니다.

관련 문제