Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Droidparts ClearableEditText

I've implemented "ClearableEditText" which mostly relies on code from DroidParts. The purpose is to have an EditText with a Drawable on the right corner (i.e. X button) in order to clear the text.

I am using a selector for the button resource which is essentially DrawableRight. This works perfect but the only problem I have is with the button getting false pressed states from it's parent (the EditText).

To reproduce:

  1. Run the project
  2. Enter text in first EditText
  3. Press anywhere inside the EditText where there's no text / drawable.

Result: selector gets PRESSED state.

Thanks for any help

like image 686
woot Avatar asked Oct 22 '22 05:10

woot


1 Answers

The only way to achieve what you're after is to set an OnTouchListener on the entire EditText and detect ACTION_PRESS within the Drawable's coordinates, then replace the selector accordingly. If you don't want to use this technique you have to create a custom View which will consist of a layout that separates the two, i.e. LinearLayout with an ImageView and a TextView as it's children.

Cheers

like image 159
Eyal Avatar answered Nov 15 '22 05:11

Eyal