title: How to set border to every Gridview Image item dynamically
body: <p>I want to Show different border of every gridview item. how can i set border to every item dynamically .</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  &gt;
  
  &lt;ImageView
      android:id="@+id/grid_item_image"
      android:layout_width="30px"
      android:layout_height="30px"
      android:src="@drawable/shape" &gt;
  &lt;/ImageView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>activity_main layout file : </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:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context=".MainActivity" &gt;
  
  &lt;GridView
      android:id="@+id/gridView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_alignParentTop="true"
      android:numColumns="15" 
      android:verticalSpacing="1dp"
      android:horizontalSpacing="1dp"
      android:background="#f3f3f3"
      &gt;
  &lt;/GridView&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Main Class:</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      gridView = (GridView) findViewById(R.id.gridView1);
  
      gridView.setAdapter(new ImageAdapter(this));
  
      gridView.setOnItemClickListener(new OnItemClickListener() {
          public void onItemClick(AdapterView&lt;?&gt; parent, View v,
                  int position, long id) {
              Toast.makeText(
                 getApplicationContext(),
                 /*((TextView) v.findViewById(R.id.grid_item_label)).getText() + */String.valueOf(position), Toast.LENGTH_SHORT).show();
              ImageView imageView = (ImageView) v.findViewById(R.id.grid_item_image);
              imageView.setBackgroundColor(Color.BLUE);
  
  
          }
      });
  </code></pre>
  
  <p>Adapter Class:</p>
  
  <pre><code> public class ImageAdapter extends BaseAdapter {
  private Context context;
  
  public ImageAdapter(Context context) {
      this.context = context;
  }
  
  public View getView(int position, View convertView, ViewGroup parent) {
  
      LayoutInflater inflater = (LayoutInflater) context
              .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
      View gridView;
  
      if (convertView == null) {
          gridView = new View(context);
          gridView = inflater.inflate(R.layout.mobile, null);
      } else {
          gridView = (View) convertView;
      }
  
      return gridView;
  }
  
  @Override
  public int getCount() {
      return 300;
  }
  
  @Override
  public Object getItem(int position) {
      return null;
  }
  
  @Override
  public long getItemId(int position) {
      return 0;
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>i have added a shape file to my custom design file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;shape xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  &lt;solid android:color="@null" /&gt;
  &lt;stroke android:width="1dp" android:color="#000000" /&gt;
  &lt;padding android:left="1dp" android:top="1dp" android:right="1dp"
  android:bottom="1dp" /&gt;
  &lt;/shape&gt;
  </code></pre>