2013-02-21 3 views
1

해시 맵 배열이 있습니다. XML 파일에서 정보를 입력하고 있습니다. 내 listview에서 이미지를 다운로드하려면 어떻게해야합니까? hmdata 이후 배열에 추가 할 수있는, 내가 이미지를 얻는 방법을 시도For 루프에서 Hashmap Array에 URL의 이미지를 다운로드 할 수 있습니까?

public void dealsCb(String url, XmlDom xml, AjaxStatus status) { 

     List<XmlDom> products = xml.tags("Product"); 
     List<HashMap<String, String>> titles = new ArrayList<HashMap<String, String>>(); 

     for (XmlDom product : products) { 
      HashMap<String, String> hmdata = new HashMap<String, String>(); 
      hmdata.put("title", product.text("Product_Name")); 
      hmdata.put("desc", product.text("Sale_Price")); 

      //NEED TO DOWNLOAD IMAGE FROM THIS URL AND THEN ADD TO ARRAY.... 
      hmdata.put("thumb", product.text("Image_URL")); 

      titles.add(hmdata); 
     } 

     String[] from = { "thumb", "title", "desc" }; 

     int[] to = { R.id.icon, R.id.title, R.id.desc }; 

     SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), titles, 
       R.layout.activity_deals_item, from, to); 

     ListView listView = (ListView) findViewById(R.id.list); 

     listView.setAdapter(adapter); 

    } 

는 비트 맵, 다음 드로어 블로 변환 만들지 만입니다 : 여기

내 코드입니다 .put은 문자열을 취합니다 ... 이미지 로딩에 무엇이 없습니까?

답변

2

여러분이 사용하고 싶은 요소를 모두 포함 할 수있는 새로운 개체를 만드는 것이 가장 좋습니다.

생성자에 대해 XmlDom을 사용하고 "title", "desc"및 "thumbnail"에 대한 getter가있는 "Product"라는 새 개체를 만들어야합니다. 이 getter는 각각 String, String 및 Bitmap을 반환합니다.

당신은 사용하여 이미지를 다운로드 할 수 있어야 HttpClient를 또는 이와 유사한 안드로이드 네트워킹 클라이언트 : HttpClient

이미지는 이미지 뷰에 사용할 비트 맵으로 변환 할 수 BitmapFactory을 사용할 수 있습니다 다운로드되면.

그런 다음 사용자 지정 "Product"개체를 목록에 추가하여 나중에 사용할 수 있습니다.

예 : 답장을 보내

public class Product{ 

    String title; 
    String desc; 
    Bitmap image; 

    public Product(XmlDom x){ 
     ... download image, and assign to instance variables ... 
    } 

    public String getTitle(){ return this.title; } 

    ... more getters ... 
} 
+1

덕분에, 나는 그것이 갈주지! 나는 또한 코드를 주셔서 감사합니다 :) – jasonflaherty

관련 문제