Android GridView Custom BaseAdapter ImageView ImageButton OnItemClick doesn´t work
<ul>
<li>i have a problem using a GridView with a CustomAdapter (extends BaseAdapter).</li>
<li>any Activity implements the OnItemClickListener.</li>
<li>if i use ImageView as item everything works fine, OnItemClick-Events will be fired/catched</li>
</ul>

<p>I have not found a useful example for a GridView with a custom BaseAdapter using ImageButton.
Has anyone an idea? Many thanks in advantage!</p>

<p>Snippets:</p>

<pre><code>class MyActivity extends Activity implements OnItemClickListener {
  ...
  @Override
  public void onCreate() {
    ...
    GridView gridview = (GridView) findViewById(R.id.gridview);
    gridview.setOnItemClickListener(this);
    gridview.setAdapter(new ImageButtonAdapter(this));
  }
  ...    
  @Override
  public void onItemClick(AdapterView&lt;?&gt; adapter, View view, int arg2, long arg3)
  {
    Log.e("onItemClick()", "arg2=" + arg2 + ", arg3=" + arg3);
  }
}


public class ImageButtonAdapter extends BaseAdapter
{
  private Context    mContext;

  public LayoutMenuAdapter(Context c)
  {
    mContext = c;
  }

  public int getCount()
  {
    return mThumbIds.length;
  }

  public Object getItem(int position)
  {
    return null;
  }

  public long getItemId(int position)
  {
    return 0;
  }

  public View getView(int position, View convertView, ViewGroup parent)
  {

    /* IF I USE THIS PART EVERYTHING WORKS FINE */

    // ImageView imageView;
    // if (convertView == null) {
    //    imageView = new ImageView(mContext);
    //    imageView.setLayoutParams(new GridView.LayoutParams(100, 100));
    //    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    //    imageView.setPadding(0, 0, 0, 0);
    //    imageView.setFocusable(false);
    //  } else {
    //    imageView = (ImageView) convertView;
    //  }
    //  imageView.setImageResource(mThumbIds[position]);
    //  return imageView;

    /* IF I USE THIS PART NO THE ACTIVITY/LISTENER RECEIVES NO EVENT */

    ImageButton imageButton;
    if (convertView == null) {
      imageButton = new ImageButton(mContext);
      imageButton.setLayoutParams(new GridView.LayoutParams(100, 100));
      imageButton.setScaleType(ImageView.ScaleType.CENTER_CROP);
      imageButton.setPadding(0, 0, 0, 0);
      imageButton.setFocusable(false);
    } else {
      imageButton = (ImageButton) convertView;
    }
    imageButton.setImageResource(mThumbIds[position]);
    return imageButton;
  }

  // references to images
  private Integer[] mThumbIds = { R.drawable.media};
}
</code></pre>
