使用SimpleAdapter将图像加载到listView中

时间:2016-01-22 01:53:13

标签: android listview hashmap simpleadapter

我遇到了这个问题。我从web url(虽然它是localHost)和其他东西中获取了图像。然而,其他东西出现了,但图像不是。我无法弄清楚出了什么问题。我发布了我班级的代码。看看这个。这是代码:

    protected String doInBackground(String... args) {
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        String json = jsonParser.makeHttpRequest(URL_CATEGORIES, "GET", params);

        Log.d("Categories JSON : ", " " + json);

        try {               
            ResultCategories = new JSONArray(json);

            if (ResultCategories != null) {                 
                for (int i = 0; i < ResultCategories.length(); i++) {
                    JSONObject c = ResultCategories.getJSONObject(i);

                    String category_id = c.getString(CATEGORY_ID);
                    String category_name = c.getString(CATEGORY_NAME);
                    String description = c.getString(CATEGORY_DESCRIPTION);
                    String pic = c.getString(CATEGORY_PICTURE);                  
                    String url_picture = "http://10.0.2.2/users/pictures/"+pic;

                    HashMap<String, Object> map = new HashMap<String, Object>();

                    map.put(CATEGORY_ID, category_id);
                    map.put(CATEGORY_NAME, category_name);
                    map.put(CATEGORY_DESCRIPTION, description);
                    map.put(CATEGORY_PICTURE, pic);


                    categoriesList.add(map);                    

                }
            }else{
                Log.d("Categories: ", "null");
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }

    protected void onPostExecute(String file_url) {
        pDialog.dismiss();
        runOnUiThread(new Runnable() {
            public void run() { 
                ListAdapter adapter = new SimpleAdapter(
                        CategoriesActivity.this, categoriesList,
                        R.layout.list_item_categories, 
                                new String[] { CATEGORY_PICTURE, CATEGORY_ID, 
                                    CATEGORY_NAME, CATEGORY_DESCRIPTION}, 
                                new int[] { R.id.image_category, R.id.category_id,  
                                    R.id.category_name, R.id.description });    
                setListAdapter(adapter);                        
            }
        });
    }

请帮助......

0 个答案:

没有答案