How to put remove cross sign in autocomplete textbox

190 Views Asked by At

if write text it automatically remove and if click on that cross all text remove from autocomplete text view, and how to mange click event of that cross sign enter image description here

1

There are 1 best solutions below

1
Neo On

Use android:drawableRight="@drawable/cross" attribute of AutoCompleteTextView.

To handle click you can use the code below :

searchMultiAutoCompleteTextView.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            final int DRAWABLE_LEFT = 0;
            final int DRAWABLE_TOP = 1;
            final int DRAWABLE_RIGHT = 2;
            final int DRAWABLE_BOTTOM = 3;

            if(event.getAction() == MotionEvent.ACTION_UP) {
                if(event.getRawX() >= (searchMultiAutoCompleteTextView.getRight() - searchMultiAutoCompleteTextView.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
                    // your action here

                 return true;
                }
            }
            return false;
        }
    });

Hope it will work for you :)