2014-03-30 48 views
0

這是我的代碼,我試圖將圖像傳遞給列表視圖,但我得到錯誤。 我如何傳遞圖像?我應該先下載到本地內存然後發送它的列表視圖?如何加載圖像並使用JSON數據傳遞給Layout?

protected String doInBackground(String... args) { 

    // Building Parameters 
    List<NameValuePair> params = new ArrayList<NameValuePair>(); 
    // getting JSON string from URL 
    JSONObject json = jParser.makeHttpRequest(url_all, "GET", params); 

    if(json == null) 
     System.out.println("NULL"); 
    else{ 
    // Check your log cat for JSON reponse 
    Log.d("All Developers: ", json.toString()); 

    try { 
     // Checking for SUCCESS TAG 
     int status = json.getInt(TAG_STATUS); 

     if (status == 1) { 
      // products found 
      // Getting Array of Products 
      developers = json.getJSONArray(TAG_all); 

      // looping through All Products 
      for (int i = 0; i < developers.length(); i++) { 
       JSONObject c = developers.getJSONObject(i); 

       // Storing each json item in variable 
       String id = c.getString(TAG_UID); 
       String name = c.getString(TAG_NAME); 
       String image = c.getString(TAG_IMAGE_PATH); 


       // creating new HashMap 
       HashMap<String, String> map = new HashMap<String, String>(); 

       // adding each child node to HashMap key => value 
       map.put(TAG_UID, id); 
       map.put(TAG_NAME, name); 
       //map.put(TAG_IMAGE_PATH, image); 

       // adding HashList to ArrayList 
       developersList.add(map); 
       //Iamge Download 
      } 
     } else { 
      System.out.println("No Data"); 
     } 
    } catch (JSONException e) { 
     e.printStackTrace(); 
    } 
    } 

    return null; 
} 
protected void onPostExecute(String file_url) { 
    // dismiss the dialog after getting all products 
    pDialog.dismiss(); 
    // updating UI from Background Thread 
    getActivity().runOnUiThread(new Runnable() { 
     public void run() { 
      /** 
      * Updating parsed JSON data into ListView 
      * */ 
      ListAdapter adapter = new SimpleAdapter(getActivity(), 
        developersList,R.layout.list_data, new String[] { TAG_UID, 
          TAG_NAME,TAG_IMAGE_PATH}, 
        new int[] { R.id.uid, R.id.name,R.id.image }); 
      // updating listview 
      lv.setAdapter(adapter); 
     } 
    }); 

} 
    } 
} 

錯誤

03-30 13:34:03.475:E/BitmapFactory(22326):無法解碼流:java.io.FileNotFoundException

+0

請更新幷包含錯誤的詳細信息,以便其他人可以幫您 – geedubb

+0

我在上面添加了錯誤 –

回答

0

你不必重新發明輪子 - 假設你有可以使用的圖像的URL nostra13 library for image loading它會爲你做所有令人討厭的工作人員(緩存處理下載\保存縮略圖等)。它也有一個exmaple項目,你可以看看更好的不理解如何使用它。

相關問題