title: Program ImageView[][] With ID - GridLayout
body: <p>I used those code to make <em>2x2 Image</em> on a <code>GridLayout</code> and it works, but there is one problem, each <code>ImageView</code> has the same ID, <code>-1</code>, so when I use <code>OnClick</code> it does not work. What can I do?</p>
  
  <p>Here the codes</p>
  
  <p><strong>activity_main.xml :</strong></p>
  
  <pre><code>&lt;GridLayout 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:id="@+id/gridLayout"
      tools:context=".MainActivity"
      android:orientation="horizontal" 
      android:columnCount="2"
      android:rowCount="2" /&gt;
  </code></pre>
  
  <p><strong>MainActivity.java :</strong></p>
  
  <pre><code>public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          GridLayout gridLayout = (GridLayout) findViewById(R.id.gridView);
  
          ImageView[][] imageViews = new ImageView[2][2];
  
          for (int i=0;i&lt;2;i++){
              for (int j=0;j&lt;2;j++){
                  imageViews[i][j] = new ImageView(MainActivity.this);
                  imageViews[i][j].setImageResource(R.mipmap.ic_launcher);
                  gridLayout.addView(imageViews[i][j]);
              }
          }  
    }
  }
  </code></pre>