0
RSS 피드에서 참조하는 파일을 다운로드하여 arraylist와 작업하고 있습니다. 지금까지는 디스크에 저장되지 않았다고 생각합니다.android, 리소스 식별자를 메모리에서 bitmap/drawable로 가져 오는 방법은 무엇입니까?
- 디스크에 저장하지 않으면 사실 리소스 식별자가 있습니까?
- 그렇다면 어떻게 검색합니까?
의무 샘플 코드 : 사전에
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;
}
감사합니다!
"디스크에 저장하지 않으면 사실 리소스 식별자가 있습니까?" - 아니, 그렇지 않을거야. "만약 그렇다면, 어떻게 되 찾을 수 있겠습니까?" - 무엇에서 무엇을 얻으려고? – CommonsWare