Javatpoint Logo
Javatpoint Logo

Android EditText with TextWatcher (Searching data from ListView)

Android EditText is a subclass of TextView. EditText is used for entering and modifying text. While using EditText width, we must specify its input type in inputType property of EditText which configures the keyboard according to input.

EditText uses TextWatcher interface to watch change made over EditText. For doing this, EditText calls the addTextChangedListener() method.

Methods of TextWatcher

  1. beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3): It is executed before making any change over EditText.
  2. onTextChanged(CharSequence cs, int arg1, int arg2, int arg3): It is executed while making any change over EditText.
  3. afterTextChanged(Editable arg0): It is executed after change made over EditText.

Example of EditText with TextWatcher()

In this example, we will implement EditText with TextWatcher to search data from ListView.

activity_main.xml

Create an activity_main.xml file in layout folder containing EditText and ListView.

File: activity_main.xml

Create another file list_item.xml in layout folder which contains data of ListView.

list_item.xm

File: list_item.xml

Activity class

Activity class

Output

android edittext 1 android edittext 2




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials