N
N
nikita0710032020-05-03 02:24:29
Java
nikita071003, 2020-05-03 02:24:29

Why can't I add an image to the listview?

I want to add an image and text to the listview so that the model and photo of the helicopter are written. Everything is loaded except for the image.
There is a listview on the screen, nothing else. The template for it is on the activity activity_listitem.

Here is the adapter code:

arraylist = new ArrayList<HashMap<String, Object>>();
        handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {

                ListAdapter listAdapter = new SimpleAdapter(show_transportActivity.this, arraylist, R.layout.activity_listitem, new String[] {HL_MODEL, ICON},
                        new int[] {R.id.listviewModel, R.id.listviewTranspotrImg});
                listViev = (ListView) findViewById(R.id.showtranspotrListView);
                listViev.setAdapter(listAdapter);
            }

        };


Here is the code for working with HashMap:

//на следующей строке вытаскивается ссылка на изображение, которая хранится в БД

                        HashMap<String, Object> Hashmap = new HashMap<String, Object>();
                        Hashmap.put(HL_MODEL, hl_model);

//тут достаю картинку по url из бд
                        Bitmap mIcon11 = null;
                        String urls = hl_image;
                        String urldisplay = urls;

                        try {
                            InputStream in = new java.net.URL(urldisplay).openStream();
                            mIcon11 = BitmapFactory.decodeStream(in);
                        } catch (Exception e) {
                            Log.e("Error", e.getMessage());
                            e.printStackTrace();
                        }
//добавляю ее в Hashmap
                        Hashmap.put(ICON, mIcon11);

                        arraylist.add(Hashmap);
                    }

                    Message msg = new Message();
                    msg.obj = arraylist;
                    handler.sendMessage(msg);




                } catch(Exception e) {
                    Log.d("ОШИБКА", e.getMessage());
                }
            }
        });

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question