title: Load images in grid view from Url
body: <p>i'm trying to fill my gridview using URL links declared on xml :
  the problem is that when i run the application ; i get an empty gridview.</p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>public class MainActivity extends Activity {
  private GridView gridView;
  private GridViewAdapter customGridAdapter;
  TypedArray imgs;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      if (android.os.Build.VERSION.SDK_INT &gt; 9) {
          StrictMode.ThreadPolicy policy = new  StrictMode.ThreadPolicy.Builder().permitAll().build();
          StrictMode.setThreadPolicy(policy);
      }
  
      gridView = (GridView) findViewById(R.id.gridView);
      customGridAdapter = new GridViewAdapter(this, R.layout.row_grid, getData());
      gridView.setAdapter(customGridAdapter);
   }
  
   private ArrayList getData() {
      final ArrayList imageItems = new ArrayList();
      // retrieve String drawable array
       imgs = getResources().obtainTypedArray(R.array.image_ids);
      this.runOnUiThread(new Runnable() {
          @Override
          public void run() {
              for (int i = 0; i &lt; imgs.length(); i++) {
                  Drawable drawable = LoadImageFromWebOperations(imgs.getString(i));
  
                  Log.i("TAG","URL de l'image : "+imgs.getString(i));
                  Log.i("TAG","contenu du drawable : "+drawable);
  
  
                  imageItems.add(new ImageItem(drawable,"Image  : "+i));
                  Log.i("TAG","image Items : "+imageItems);
              }
  
          }
      });
  
  
      return imageItems;
  
   }
   private Drawable LoadImageFromWebOperations(String url)
   {
      try
      {
          InputStream is = (InputStream) new URL(url).getContent();
          Drawable d = Drawable.createFromStream(is, "src name");
          return d;
       }catch (Exception e) {
           System.out.println("Exc="+e);
          return null;
       }
   }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>GridViewAdapter</strong></p>
  
  <pre><code> public class GridViewAdapter extends ArrayAdapter&lt;ImageItem&gt; {
   private Context context;
   private int layoutResourceId;
   private ArrayList&lt;ImageItem&gt; data = new ArrayList&lt;ImageItem&gt;();
  
   public GridViewAdapter(Context context, int layoutResourceId,
                         ArrayList&lt;ImageItem&gt; data) {
      super(context, layoutResourceId, data);
      this.layoutResourceId = layoutResourceId;
      this.context = context;
      this.data = data;
   }
  
   @Override
   public View getView(int position, View convertView, ViewGroup parent) {
      View row = convertView;
      ViewHolder holder = null;
  
      if (row == null) {
          LayoutInflater inflater = ((Activity) context).getLayoutInflater();
          row = inflater.inflate(layoutResourceId, parent, false);
          holder = new ViewHolder();
          holder.imageTitle = (TextView) row.findViewById(R.id.text);
          holder.image = (ImageView) row.findViewById(R.id.image);
          row.setTag(holder);
      } else {
          holder = (ViewHolder) row.getTag();
      }
  
      ImageItem item = data.get(position);
      holder.imageTitle.setText(item.getTitle());
      holder.image.setImageDrawable(item.getImage());
      return row;
   }
  
   static class ViewHolder {
      TextView imageTitle;
      ImageView image;
   }
   }
  </code></pre>
  
  <p><strong>array.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources&gt;
  
  &lt;string-array name="image_ids"&gt;
      &lt;item&gt;http://media-cdn.tripadvisor.com/media/photo-s/02/83/a6/00/mon-port-hotel-spa.jpg&lt;/item&gt;
      &lt;item&gt;http://media-cdn.tripadvisor.com/media/photo-s/02/83/a6/00/mon-port-hotel-spa.jpg&lt;/item&gt;
      &lt;item&gt;http://media-cdn.tripadvisor.com/media/photo-s/02/83/a6/00/mon-port-hotel-spa.jpg&lt;/item&gt;
      &lt;item&gt;http://media-cdn.tripadvisor.com/media/photo-s/02/83/a6/00/mon-port-hotel-spa.jpg&lt;/item&gt;
  
  
  &lt;/string-array&gt;
  
  &lt;/resources&gt;
  </code></pre>
  
  <p><strong>row_grid.xml</strong></p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_marginTop="5dp"
  android:orientation="vertical"
  android:padding="5dp"
  android:clickable="true"
  android:focusable="true"&gt;
  
  &lt;ImageView
      android:id="@+id/image"
      android:layout_width="100dp"
      android:layout_height="100dp" &gt;
  &lt;/ImageView&gt;
  
  &lt;TextView
      android:id="@+id/text"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="5dp"
      android:gravity="center"
      android:textSize="12sp" &gt;
  &lt;/TextView&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="#f0f0f0"
  tools:context=".MainActivity" &gt;
  
  &lt;GridView
      android:id="@+id/gridView"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_margin="5dp"
      android:columnWidth="100dp"
      android:gravity="center"
      android:numColumns="auto_fit"
      android:verticalSpacing="5dp"
      android:drawSelectorOnTop="true"
      android:stretchMode="columnWidth" &gt;
  &lt;/GridView&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>