I have created an EditText
for search, which contains on the left side a search icon and on the right side of icon:
<EditText
android:id="@+id/Search"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:drawableLeft="@android:drawable/ic_menu_search"
android:drawableRight="@android:drawable/ic_delete"
android:hint="Search Product .." >
</EditText>
I want to know how can I clear the content of EditText
when I click the cross button.
Thank you in advance.
Exemple I made:
An improved answer by @aristo_sh from Handling click events on a drawable within an EditText
I prefer using another custome
Edittex
as below clearable edittext. You can use it in xml as normal edittext. To listen to clear event, you cansetListener
for yourClearableEdittext
Edit: I forgot
TextWatcherAdapter
, actually it's only customeTextWatcher
:Try this:
activity_main.xml
MainActivity.java