Skip to content Skip to sidebar Skip to footer

How To Perform Click On Textinputlayout Endicon Button

I know that it is possible to perform a click on a view like this : view.PerformClick() How do I do it on TextInputLayout EndIcon button? Update The problem is that I have a bunch

Solution 1:

textinput.setEndIconOnClickListener(newView.OnClickListener() {
            @OverridepublicvoidonClick(View v) {
                // do some code
            }
        });

hope it helps..

Solution 2:

Thank you so much for you clear and helpful answer.I did a little trick that worked and i wanna share my answer to everyone who will need it.

First thing i did is get the string value of my view :

Log.d("tag", String.valueOf(v));

i got that : com.google.android.material.internal.CheckableImageButton{ba604a VFED..C.. ...P.... 8,3-104,99 #7f090125 app:id/text_input_end_icon}

and like i suspected then icon is a different view of the text field layout with different id (in the end of the string value of the view). So i changed my if condition from if (v.getId() == R.id.start_date_Layout) to if (v.getId() == R.id.text_input_end_icon), and it work now

i hope this answer will be helpful to someone, thank you again for all your answer

Solution 3:

EndIcon in TextInputLayout is of type CheckableImageButton and its id is R.id.text_input_end_icon (use R.id.text_input_start_icon for StartIcon). To simulate clicks, you need to find the button using findViewById, then cast it as a CheckableImageButton and call performClick().

In your case:

inputLayout.findViewById<CheckableImageButton>(R.id.text_input_end_icon)?.performClick()

Solution 4:

view.setOnTouchListener(newView.OnTouchListener() {
     @OverridepublicbooleanonTouch(View v, MotionEvent event) {
          finalintDRAWABLE_LEFT=0;
          finalintDRAWABLE_TOP=1;
          finalintDRAWABLE_RIGHT=2;
          finalintDRAWABLE_BOTTOM=3;

          if(event.getAction() == MotionEvent.ACTION_UP) {
             if(event.getRawX() >= (quantity.getRight() - quantity.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
                 // your action here// For example:
                 view.getText().clear();
                 returntrue;
              }
          }
          returnfalse;
      }
});

Post a Comment for "How To Perform Click On Textinputlayout Endicon Button"