title: Android: how to get grid-view item Tag by its position from with-in Another grid-view's set-on-item-click listener function?
body: <p>How can I get a <code>grid-view</code>'s item tag by its position and have to get from another <code>grid-view</code>'s item click listener function.</p>
  
  <pre><code>gridview2.setOnItemClickListener(new OnItemClickListener() 
  {
      public void onItemClick(AdapterView&lt;?&gt; parent, View v,
                              int position, long id) 
      {
          int i=(Integer)gridview1.getChildAt(gridview1s_position).getTag();---&gt; it is returning Null     
      }  
  });
  </code></pre>
  
  <p>MY <code>gridview1.setOnitemClicklistener</code> and <code>gridview2.setonitemclicklistener</code> are in the same file (<code>MainActivity.java</code>)</p>
  
  <p>But the <code>gridview1</code> adapter is a <code>ImageAdapter.java</code>(this is for setting the images in the gridview1) and <code>gridview2</code> adapter is <code>imageadapter2.java</code>(this is for setting black images so that the <code>gridview2</code> looks like a box with rows and columns, otherwise it is showing like a Bold line because we didn't put anything in the gridview)</p>
  
  <pre><code>gridview1.setOnItemClickListener(new OnItemClickListener() 
      {
          public void onItemClick(AdapterView&lt;?&gt; parent, View v,int position, long id) 
          {  
              int tag=(Integer)gridview1.getChildAt(position).getTag();//this returning the tag
          }
       }); 
  </code></pre>
  
  <p>ImageAdapter1.java</p>
  
  <pre><code> public View getView(int arg0, View arg1, ViewGroup arg2) {
      // TODO Auto-generated method stub
  
  
      if(arg1!=null)
      {
          imv=(ImageView)arg1;
      }
      else
      {
          imv=new ImageView(cont);
          imv.setLayoutParams(new GridView.LayoutParams(40,40));
          imv.setScaleType(ScaleType.CENTER_CROP);
          imv.setPadding(0,0,0,0);
  
      }
      imv.setImageResource(imageid[arg0]);//imageid aray is having drawable images
      imv.setTag(imageid[arg0]);
      return imv;
  
  }
  </code></pre>
  
  <p>gridview2</p>
  
  <pre><code>gridview2.setOnItemClickListener(new OnItemClickListener() 
      { 
        ImageAdapter ia=new ImageAdapter(getApplicationContext());
  public void onItemClick(AdapterView&lt;?&gt; parent, View v,int position, long id) 
           {  
                  ImageView imv;
                    if(v!=null)
              {
                  imv=(ImageView)v;
              }
              else
              {
                  imv=new ImageView(getApplicationContext());
                  imv.setLayoutParams(new GridView.LayoutParams(40,40));
                  imv.setScaleType(ScaleType.CENTER_CROP);
                  imv.setPadding(0,0,0,0);
                  imv.setBackgroundColor(5555);
  
              }
  
                    imv.setImageResource(ia.imageid[tt]); 
          }
  });
  </code></pre>