title: How to add gridview setOnItemClickListener
body: <p>I have a GridView with 81 buttons on it. I want to add clicklistener to this gridview but it is not available. I have added the OnItemClickListener but it is not working and I cannot understand why. There is no error with the code. The only thing not working is the OnItemClickListener.</p>
  
  <p>My gridview children which has a button on it(gridview_members.xml);</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  &gt;
  
  &lt;Button
      android:id="@+id/city"
      android:layout_width="183dp"
      android:layout_height="90dp"
      android:textSize="19sp"
      android:textStyle="bold"
      android:text="Code\n\nCity"
      android:gravity="center"
      android:background="@drawable/city_btn_tablet" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>My ImageAdapter class;</p>
  
  <pre><code>public class ImageAdapter extends BaseAdapter {
  private Context mContext;
  
  public ImageAdapter(Context c) {
      mContext = c;
  }
  
  public int getCount() {
      return 81;
  }
  
  public Object getItem(int position) {
      return null;
  }
  
  public long getItemId(int position) {
      return 0;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
  
      LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
      View gridView;
  
      gridView =new View(mContext);
  
      gridView = inflater.inflate(R.layout.gridview_members, null);
  
      Button city = (Button) gridView.findViewById(R.id.city);
  
      return gridView;
  }
  
  }
  </code></pre>
  
  <p>Gridview implementation on activity_main.xml ;</p>
  
  <pre><code>&lt;GridView
  android:id="@+id/gridview"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:horizontalSpacing="5dp"
  android:verticalSpacing="5dp"
  android:gravity="center"
  android:stretchMode="columnWidth"
  android:numColumns="6" &gt;
  &lt;/GridView&gt;
  </code></pre>
  
  <p>And finally my MainActivity.java file;</p>
  
  <pre><code>public class MainActivity extends Activity{
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      GridView gridview = (GridView) findViewById(R.id.gridview);
      gridview.setAdapter(new ImageAdapter(this));
  
      gridview.setOnItemClickListener(new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) {
              Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show();
          }
      });
  }
  }
  </code></pre>