title: Get Image from Urls with AsyncTask
body: <p>I am sure this is not a new question. Unfortunately, after fighting for this activity over 20 hours, I'm still cannot find out the solution. Could you please give me a helping hand. I will be very appreciate.</p>
  
  <p>Hey is my question. I would like to show Image from different urls to a girdView layout. However, my code didn't work so the screen show nothing. Could you guy please help me to solve this?</p>
  
  <p>Below is my MainActivity Class</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      String [] imgUrlList = {
              "http://image.tmdb.org/t/p/w500/cGOPbv9wA5gEejkUN892JrveARt.jpg",
              "http://image.tmdb.org/t/p/w500/6FxOPJ9Ysilpq0IgkrMJ7PubFhq.jpg",
              "http://image.tmdb.org/t/p/w500/z09QAf8WbZncbitewNk6lKYMZsh.jpg",
              "http://image.tmdb.org/t/p/w500/kqjL17yufvn9OVLyXYpvtyrFfak.jpg"
      };
  
  
      mMovieAdapter = new MyAdapter(this, imgUrlList);
      GridView gridview = (GridView) findViewById(R.id.gridView);
      gridview.setAdapter(mMovieAdapter);
  
  }
  
  public class MyAdapter extends ArrayAdapter&lt;String&gt;{
      private final Activity context;
      private final String[] imgUrlList;
  
      public MyAdapter (Activity context, String[] imgUrlList){
          super(context, R.layout.image_item);
          this.context = context;
          this.imgUrlList = imgUrlList;
      }
  
      public View getView (int position, View view, ViewGroup parent){
          LayoutInflater inflater = context.getLayoutInflater();
          View rootView = inflater.inflate(R.layout.image_item, null, true);
  
          new DownloadImageTask((ImageView) rootView.findViewById(R.id.imageItem)).execute(imgUrlList[position]);
          ImageView imageView = (ImageView) rootView.findViewById(R.id.imageItem);
          imageView.setImageURI(Uri.parse(imgUrlList[position]));
  
          return rootView;
      }
  }
  
  private class DownloadImageTask extends AsyncTask &lt;String, Void, Bitmap&gt;{
  
      ImageView poster;
  
      public DownloadImageTask(ImageView poster) {
          this.poster = poster;
      }
  
      protected Bitmap doInBackground(String... urls){
          String imageUrls = urls[0];
          Bitmap moviePoster = null;
          try {
              InputStream in = new java.net.URL(imageUrls).openStream();
              moviePoster = BitmapFactory.decodeStream(in);
          } catch (Exception e) {
              Log.e("Error", e.getMessage());
              e.printStackTrace();
          }
          return moviePoster;
      }
  
      @Override
      protected void onPostExecute(Bitmap result) {
          poster.setImageBitmap(result);
      }
  }
  </code></pre>
  
  <p>Below is my xml (activity_main) file</p>
  
  <pre><code>&lt;GridView
      android:id="@+id/gridView"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:columnWidth="185dp"
      android:numColumns="auto_fit"/&gt;
  </code></pre>
  
  <p>I also have a imageView file call image_item</p>