title: Hide AlertDialog when click on List item
body: <p>I have created an alert dialog with <code>TextView</code> and a List with options. The user can select one item from the list or add a new one with the <code>EditText</code>.</p>
  
  <p>The problem is that the <code>alertDialog</code> is only hidden when I give the button to add new and not when I click on an item in the list.</p>
  
  <pre><code>final AlertDialog.Builder builder = new AlertDialog.Builder(this);
      final LayoutInflater inflater = getLayoutInflater();
      final View dialogGroup = inflater.inflate(R.layout.select_group_layout, null);
      final EditText newGroup = dialogGroup.findViewById(R.id.new_group);
      final ListView listView = dialogGroup.findViewById(R.id.groups_list);
  
  
      listView.setAdapter(new ArrayAdapter&lt;&gt;(this, android.R.layout.simple_list_item_1, list));
      listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                  int position, long id) {
              HelperTools.showInfo("Selected group: " + ((TextView) view).getText(), getClass());
          }
      });
  
      builder.setView(dialogGroup)
              .setTitle(R.string.departments_txt)
              .setPositiveButton("Añadir", new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                      contactDepartment = newGroup.getText().toString();
                      HelperTools.showInfo("Selected group: " + contactDepartment, getClass());
                  }
              });
  
      if (list.size() != 0) {
          builder.create();
          builder.show();
      }
  </code></pre>
  
  <p>How can I hide the AlertDialog when they pick a ListView item?</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Final code:</p>
  
  <pre><code>    final AlertDialog builder = new AlertDialog.Builder(this).create();
      final LayoutInflater inflater = getLayoutInflater();
      final View dialogGroup = inflater.inflate(R.layout.select_group_layout, null);
      final EditText newGroup = dialogGroup.findViewById(R.id.new_group);
      final ListView listView = dialogGroup.findViewById(R.id.groups_list);
  
  
      listView.setAdapter(new ArrayAdapter&lt;&gt;(this, android.R.layout.simple_list_item_1, list));
      listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                  int position, long id) {
              HelperTools.showInfo("Selected group: " + ((TextView) view).getText(), getClass());
              builder.dismiss();
          }
      });
  
      builder.setView(dialogGroup);
      builder.setTitle(R.string.departments_txt);
      builder.setButton(Dialog.BUTTON_POSITIVE, "Añadir", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialogInterface, int i) {
              contactDepartment = newGroup.getText().toString();
              HelperTools.showInfo("Selected group: " + contactDepartment, getClass());
          }
      });
  
      if (list.size() != 0) {
          builder.show();
      }
  </code></pre>