简体   繁体   中英

Android set an image to imageview from JSON url

 protected void onPostExecute(String s) {
            super.onPostExecute(s);
            //System.out.println("alınan data:" + s);

            try{
                JSONObject jsonObject = new JSONObject(s);


                String poster = jsonObject.getString("Poster");

                InputStream is = (InputStream) new URL(poster).getContent();
                Drawable d = Drawable.createFromStream(is, "src name");
                Poster.setImageDrawable(d);


                String Title = jsonObject.getString("Title");
                tryText.setText("Title: " + Title);

                String Year = jsonObject.getString("Year");
                movieYear.setText("Year: " + Year);



            }catch (Exception e){

            }
        }

I want to show image from JSONObject url but dind't find a way. There is an EditText and it changes url dynamically when button clicked.

You can try this

  Bitmap image = null;
  try {
    InputStream in = new URL(poster).openStream();
    image = BitmapFactory.decodeStream(in);
  } catch (Exception e) {
      Log.e("Error", e.getMessage());
      e.printStackTrace();
  }
 if(image!=null)
      imageView.setImageBitmap(image);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM