title: AlertDialog - DialogInterface onClick OR ListView onClick not Getting Called on Item Click
body: <p><strong>I WANT TO DISMISS ALERT DIALOG</strong> on click of <strong>ListView</strong> Item which I have bind in Custom Array Adapter.</p>
  <h2>onClick of DialogInterface OR OnItemClickListener of ListView not getting called on click of Item.</h2>
  <p>I have used following code to bind <a href="https://api.postalpincode.in/pincode/364710" rel="nofollow noreferrer">this</a> API:</p>
  <p>Getting Data:</p>
  <pre><code>RetrofitInterface retrofitInterface = RetrofitClient.getPinCodeApiService();
  Call&lt;List&lt;PinCodeModel&gt;&gt; call = retrofitInterface.getAreaDetailsByPinCode(pinCode);
  call.enqueue(new Callback&lt;List&lt;PinCodeModel&gt;&gt;() {
      @Override
      public void onResponse(Call&lt;List&lt;PinCodeModel&gt;&gt; call, Response&lt;List&lt;PinCodeModel&gt;&gt; response) {
          if (response.isSuccessful()) {
              List&lt;PinCodeModel&gt; list = response.body();
              if (list != null) {
                  PinCodeModel model = list.get(0);
                  if (model.getStatus().equalsIgnoreCase(RetrofitClient.SUCCESS)) {
                      List&lt;PostOffice&gt; postOffices = model.getPostOffice();
                      if (postOffices.size() &gt; 0) {
                          showAreaDialog(postOffices);
                      } else {
                          Toast.makeText(AddMyBusinessActivity.this, model.getMessage(), Toast.LENGTH_SHORT).show();
                      }
                  } else {
                      Toast.makeText(AddMyBusinessActivity.this, model.getMessage(), Toast.LENGTH_SHORT).show();
                  }
              } else {
                  Toast.makeText(AddMyBusinessActivity.this, &quot;Unable to fetch data, Try again.&quot;, Toast.LENGTH_SHORT).show();
              }
          } else {
              Toast.makeText(AddMyBusinessActivity.this, getString(R.string.string_something_went_wrong), Toast.LENGTH_SHORT).show();
          }
      }
  
      @Override
      public void onFailure(Call&lt;List&lt;PinCodeModel&gt;&gt; call, Throwable t) {
          Toast.makeText(AddMyBusinessActivity.this, getString(R.string.string_something_went_wrong), Toast.LENGTH_SHORT).show();
          Crashlytics.logException(t);
          Log.e(&quot;TAG&quot;, &quot;onFailure: &quot; + t.getLocalizedMessage());
      }
  });
  </code></pre>
  <p>Showing Dialog:</p>
  <pre><code>private void showAreaDialog(List&lt;PostOffice&gt; postOffices) {
      AlertDialog.Builder builderSingle = new AlertDialog.Builder(AddMyBusinessActivity.this);
  
      ListView listView = new ListView(this);
      AreaAdapter areaAdapter = new AreaAdapter(this, postOffices);
      listView.setAdapter(areaAdapter);
      builderSingle.setTitle(&quot;Select Area&quot;);
      builderSingle.setNegativeButton(&quot;cancel&quot;, new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
              dialog.dismiss();
          }
      });
      listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
              PostOffice strName = postOffices.get(i);
              Toast.makeText(AddMyBusinessActivity.this, strName.getName(), Toast.LENGTH_SHORT).show();
              alertDialog.dismiss();
          }
      });
      builderSingle.setView(listView);
      alertDialog = builderSingle.show();
  }
  </code></pre>
  <p>I have tried this one too:</p>
  <pre><code> AlertDialog.Builder builderSingle = new 
   AlertDialog.Builder(AddMyBusinessActivity.this);
  
      //ListView listView = new ListView(this);
      AreaAdapter areaAdapter = new AreaAdapter(this, postOffices);
      builderSingle.setAdapter(areaAdapter, new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialogInterface, int i) {
              PostOffice strName = postOffices.get(i);
              Toast.makeText(AddMyBusinessActivity.this, strName.getName(), Toast.LENGTH_SHORT).show();
              Log.d(&quot;TAG&quot;, &quot;onItemClick: &quot;);
              alertDialog.cancel();
          }
      });
      builderSingle.setTitle(&quot;Select Area&quot;);
      builderSingle.setNegativeButton(&quot;cancel&quot;, new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
              dialog.dismiss();
          }
      });
  </code></pre>
  <p><a href="https://i.stack.imgur.com/ooBvCl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ooBvCl.png" alt="enter image description here" /></a></p>
  <p>I am clicking on any item but nothing happen. Can anyone please help me?</p>
  <p>I HAVE TRIED ALL THE RELATED LINKS on <strong>STACKOVERFLOW</strong> but didn't get succeed.</p>
  <ul>
  <li><a href="https://stackoverflow.com/a/10368030/1318946">https://stackoverflow.com/a/10368030/1318946</a></li>
  <li><a href="https://stackoverflow.com/a/44606815/1318946">https://stackoverflow.com/a/44606815/1318946</a></li>
  </ul>
  <p>I have also tried to make xml file with listview and inflate it to AlertDialog but now worked for me.</p>
  <p><strong>Edited:</strong></p>
  <p>Here is <strong>row_layout_area.xml</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;layout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;&gt;
  
      &lt;androidx.cardview.widget.CardView
          android:id=&quot;@+id/parentView&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:clickable=&quot;true&quot;
          android:focusable=&quot;true&quot;
          android:foreground=&quot;?attr/selectableItemBackground&quot;
          app:cardBackgroundColor=&quot;@android:color/white&quot;
          app:cardCornerRadius=&quot;@dimen/_4sdp&quot;
          app:cardElevation=&quot;@dimen/_2sdp&quot;
          app:cardPreventCornerOverlap=&quot;true&quot;
          app:cardUseCompatPadding=&quot;true&quot;&gt;
  
          &lt;androidx.constraintlayout.widget.ConstraintLayout
              android:layout_width=&quot;match_parent&quot;
              android:padding=&quot;@dimen/_8sdp&quot;
              android:layout_height=&quot;match_parent&quot;&gt;
  
              &lt;TextView
                  android:id=&quot;@+id/area_text_view&quot;
                  android:layout_width=&quot;0dp&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:ellipsize=&quot;end&quot;
                  android:lines=&quot;1&quot;
                  android:textColor=&quot;@color/colorAccent&quot;
                  android:textSize=&quot;17sp&quot;
                  app:layout_constraintEnd_toEndOf=&quot;parent&quot;
                  app:layout_constraintStart_toStartOf=&quot;parent&quot;
                  app:layout_constraintTop_toTopOf=&quot;parent&quot;
                  tools:text=&quot;Soham ERP Pvt. Ltd.&quot; /&gt;
  
              &lt;TextView
                  android:id=&quot;@+id/city_state_country&quot;
                  android:layout_width=&quot;0dp&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginTop=&quot;@dimen/_4sdp&quot;
                  android:ellipsize=&quot;end&quot;
                  android:textColor=&quot;@android:color/background_dark&quot;
                  app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
                  app:layout_constraintEnd_toEndOf=&quot;parent&quot;
                  app:layout_constraintStart_toStartOf=&quot;@+id/area_text_view&quot;
                  app:layout_constraintTop_toBottomOf=&quot;@+id/area_text_view&quot;
                  tools:text=&quot;Software, Software Company&quot; /&gt;
  
          &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
      &lt;/androidx.cardview.widget.CardView&gt;
  &lt;/layout&gt;
  </code></pre>