How to load an image from a Url into an Imageview

Asked

Viewed 746 times

-1

 rs = statement.executeQuery(query);
            List<Map<String, String>> data = null;
            data = new ArrayList<Map<String,String>>();
            while(rs.next()){
                Map<String, String> datanum = new HashMap<String, String>();
                datanum.put("A", rs.getString("Nome").trim().toString());
                datanum.put("B", "http://acme.com.br/pic/1/" + rs.getString("Al_Matricula").trim().toString() + ".jpg");  // <<<--- URL
                datanum.put("C", rs.getString("Id").trim().toString());
                datanum.put("D", rs.getString("Ean").trim().toString());
                datanum.put("E", rs.getString("Code").trim().toString());
                data.add(datanum);
            }
            String[] from = {"A", "B", "C", "D", "E"};
            int[] views = { R.id.tvNome,
                            R.id.tvTemp,   //  <<<----  preciso que meu imageview que esta dentro do listview carregue esta imagem 
                            R.id.tvId,
                            R.id.tvEan,
                            R.id.tvCode };    



        AD = new SimpleAdapter(this, data, R.layout.activity_modelo, from, views);
        lst_Alunos.setAdapter(AD);

1 answer

0

Use the library Glide, follows the example of how to implement in the code:

  Glide.with(this)
                    .load(urlImages.get("SUA URL"))
                    .asBitmap()
                    .listener(new RequestListener<String, Bitmap>() {
                        @Override
                        public boolean onException(Exception e, String model, com.bumptech.glide.request.target.Target<Bitmap> target, boolean isFirstResource) {
                            // AÇÕES A SE EXECUTAR CASO HOUVER ERRO
                            return false;
                        }

                        @Override
                        public boolean onResourceReady(Bitmap resource, String model, com.bumptech.glide.request.target.Target<Bitmap> target, boolean isFromMemoryCache, boolean isFirstResource) {
                            // AÇÕES A SE EXECUTAR QUANDO FOR CARREGADA A IMAGEM
                            return false;
                        }
                    }).into(SUA IMAGEVIEW);
  • The code you shared may be functional for another condition. It does not apply to my need. Thank you for your availability.

  • What is your need? By the question you just want to upload a url to imageView, and the code meets the need

  • Your image is inside an item for Listview?

  • If you are Voce you have to execute the code in the list Adapter

  • Hello Edson! Maybe I wasn’t very clear. I’d like to upload the "url" image to R.id.ivImage, cast and everything. &#xA;Eu encontrei uma forma de carregar a imagem porém tem que clicar no listView&#xA;&#xA;ImageView iv_Imagem = ( ImageView ) view.findViewById(R.id.ivImagem);&#xA;TextView tv_Temp = ( TextView ) view.findViewById(R.id.tvTemp);&#xA;String urlImage = tv_Temp.getText(). toString(); Picasso.get(). load(urlImage). into(iv_Image);

  • Yes, it’s inside a Listview

  • How do I run this inside the Adapter, that’s where I’m screwing around.

  • Paste in your question the listview Adapter

  • The class that Voce mounts the Adapter and if you have a separate Holder send the Holder class

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.