title: Android : Add a listener to an icon in a text field
body: <p>i am a beginner  in application development and i like to ask a question that i tried my best to get an answer in google but i failed.
  So,</p>
  <p>in my application (in java) i am using too text fields :</p>
  <pre><code>  &lt;com.google.android.material.textfield.TextInputLayout
  
          android:layout_marginBottom=&quot;20dp&quot;
          android:id=&quot;@+id/start_date_Layout&quot;
          style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginHorizontal=&quot;20dp&quot;
          app:helperText=&quot;Start Date&quot;
          app:endIconMode=&quot;custom&quot;
          app:endIconDrawable=&quot;@drawable/ic_date&quot;
  
          &gt;
  
          &lt;com.google.android.material.textfield.TextInputEditText
              android:id=&quot;@+id/start_date&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:hint=&quot;dd/mm/yy&quot;
  
              /&gt;
  
      &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  </code></pre>
  <p>I added a listener to my end icon like that :</p>
  <pre><code>this.startDateLayout = v.findViewById(R.id.start_date_Layout);
  this.startDateLayout.setEndIconOnClickListener(this);
  </code></pre>
  <p>My problem is when i try to get the view that the user clicked :</p>
  <pre><code> @Override
  public void onClick(View v) {
      
      if (v.getParent() == this.startDateLayout){
         
          Toast.makeText(this.context, &quot;click&quot;, Toast.LENGTH_LONG).show();
      }
      
  }
  </code></pre>
  <p>the toast never appear and the if condition is never true, my question is how can i get the view on witch the user clicked. thanks for reading i hope i was clear as much as possible.</p>