Android: how to get grid-view item Tag by its position from with-in Another grid-view's set-on-item-click listener function?
<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 gridview1.setOnitemClicklistener and gridview2.setonitemclicklistener are in the same file (MainActivity.java)</p>

<p>But the gridview1 adapter is a ImageAdapter.java(this is for setting the images in the gridview1) and </p>

<p>gridview2 adapter is imageadapter2.java(this is for setting black images so that the </p>

<p>gridview2 looks like a box with rows and </p>

<p>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>
