title: Android GridView item click Alert Dialog
body: <p>I have an <code>AlertDialog</code> with the <code>GridView</code> to choose a color, now I want to close the <code>AlertDialog</code> when click item . How can I do?</p>
  
  <pre><code>private void Alert_Colori() {
      final AlertDialog.Builder customDialog = new AlertDialog.Builder(this);        
      LayoutInflater inflater = this.getLayoutInflater();
      View view = inflater.inflate(R.layout.color_picker, null);
  
      GridView gridViewColors = (GridView) view.findViewById(R.id.gridViewColors);
      gridViewColors.setAdapter(new ColorPickerAdapter(this));
  
      gridViewColors.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
           //here close the dialog
          }
      });
  
      customDialog.setView(view);
      customDialog.setNegativeButton("Annulla", new DialogInterface.OnClickListener() {
  
          @Override
          public void onClick(DialogInterface dialog, int arg1) {
              dialog.dismiss();
  
          }
      });
      customDialog.setView(view);
      customDialog.show();
  }
  </code></pre>