2012-11-30 41 views
2

我正在研究一個應用程序,它需要獲得新的標題並在listView中添加拇指圖像,並且我不知道如何將照片url轉換爲圖像並放入listView我在這裏的代碼:用json解析圖像到ListView旁邊的ListView

我可以得到圖像的網址,但我不知道該怎麼做才能添加到我得到的文本旁邊的listView,任何幫助?

private class theJob extends AsyncTask<String, Void, ArrayList<HashMap<String, String>>>{ 




    @Override 
    protected void onPostExecute(ArrayList<HashMap<String, String>> result) { 
     ListAdapter adapter = new SimpleAdapter(MainActivity.this, result, R.layout.list_item, 
        new String[] {TAG_CAT_NAME }, new int[] {R.id.label }); 
      setListAdapter(adapter); 
      Log.d("adapter", "works"); 

    } 

    @Override 
    protected ArrayList<HashMap<String, String>> doInBackground(
      String... params) { 
     // TODO Auto-generated method stub 
     Log.d("Format", params[0]); 
     Log.d("URL", params[1]); 

     ArrayList<HashMap<String, String>> cat = new ArrayList<HashMap<String,String>>(); 
     JsonParser jparser = new JsonParser(); 
     Log.d("url", "to the other class"); 
     JSONArray jArray = jparser.getJSONfronUrl(params[1]); 
      Log.d("json array", "created"); 
      try{ 
       for(int i=0 ; i< jArray.length() ; i++){ 
        JSONObject joob = jArray.getJSONObject(i); 
        Log.d("jobj", "done"); 
        String title = joob.getString(params[0]); 
        Log.d(TAG_CAT_NAME, "done"); 
        cat_id = joob.getString(TAG_CAT_ID); 
        Log.d(TAG_CAT_ID, cat_id); 
        cat_url.add(i, joob.getString(TAG_CAT_URL)) ; 
        HashMap<String, String> map = new HashMap<String, String>(); 
        map.put(params[0], title); 

        cat.add(map); 
       } 

      }catch(JSONException e){ 
       e.printStackTrace(); 
      } 
      Log.d("Going to ADAPTER", "working"); 
      return cat; 
    } 
} 

回答

0

下面是一個使用Googe example這將幫助你想要的東西:)

更新

在這裏,您將罰款約在list view圖像延遲加載更多的幫助。

+0

謝謝..它確實可以工作但開車送我到另一個問題 的imageloader.java沒有影像傳回當我打電話從我的lazyadapter.java(工作延伸的AsyncTask ..)類.. 我不知道爲什麼! – vezikon

+0

實際上沒有幫助..我仍然無法做到這一點 – vezikon

0

您可以使用SmartImageView,它是Android標準ImageView的替代品,它可以從URL或用戶的聯繫人地址簿中加載圖像。圖像緩存到內存和磁盤以實現超快速加載。

https://github.com/loopj/android-smart-image-view