列表视图中的图像不显示

时间:2013-08-01 14:39:44

标签: java android image listview

我试图将图像添加到列表视图中的列表项目,但图像不显示,这对我来说似乎很奇怪。我在布局xml中设置了imageview,我觉得我正确地解码了位图。无论如何这就是我所做的。

JSONArray array = jsn.getJSONArray("options");

                if(array.length()==0)
                    Log.d("Friends?","No friends");
                if(array.length()>0){
                for (int i = 0; i < array.length(); i++) {
                   // Log.i("name", array.getJSONObject(i).getString("name"));
                    JSONObject c = array.getJSONObject(i);

                    // Storing each json item in variable
                    String id = c.getString("contact_id");
                    String name = c.getString("name");
                    //String picture=c.getString("picture");
                    java.io.InputStream in;
                      in = new java.net.URL("http://www.example.com/images/01e7b07355b4e6042b7268e6ad88fcc5.jpg").openStream();
                    final Bitmap icon = BitmapFactory.decodeStream(in);
                /*  runOnUiThread(new Runnable(){

                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            ImageView image = (ImageView) findViewById(R.id.profilepicture);
                            image.setImageBitmap(icon);
                        }

                    });*/
                   // Log.i("picture_url", picture);
                    // creating new HashMap
                    HashMap<String, Object> map = new HashMap<String, Object>();

                    // adding each child node to HashMap key => value
                    map.put("contact_id", id);
                    map.put("name", name);
                    map.put("picture", icon);

                    // adding HashList to ArrayList
                    productsList.add(map);

protected void onPostExecute(String file_url) {
            // dismiss the dialog after getting all products

            // updating UI from Background Thread
            runOnUiThread(new Runnable() {
                public void run() {

                    ListAdapter adapter = new SimpleAdapter(
                            Contacts.this, productsList,
                            R.layout.list_item, new String[] { "contact_id","name", "picture"},
                            new int[] { R.id.pid, R.id.name, R.id.profilepicture });
                    // updating listview
                    setListAdapter(adapter);
                }
            });

        }

但是,图像没有显示,我不知道错误。

0 个答案:

没有答案