Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify addTextChangedListener in XML

Tags:

android

Is there any property for EditText I can specify TextChangedListener? I know it has 3 methods, so I want just specify value of property like below

 <EditText
     android:afterTextChanged="myAfterHandler"

However I am getting compilation errors. I can add on click listener in same way so I am wondering what is wrong on text changed?

I know I can obtain view at certain time in Java code and call add listener, but this solution looks really ugly.

like image 621
user2305886 Avatar asked Dec 03 '13 03:12

user2305886


People also ask

How do I use addTextChangedListener?

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.

What is the use of TextWatcher in android?

Notifications Stay organized with collections Save this page to your Developer Profile to get notifications on important updates. Save and categorize content based on your preferences. Base class that can be used to implement virtualized lists of items.


1 Answers

Android's Data Binding Library now supports generating xml attributes for setters that exist in the view's class.

If you have data binding enabled, all you need to do is use the app namespace (don't forget to declare the namespace), so something like app:addTextChangedListener="@{someobject.textwatcherfield}"

like image 50
yincrash Avatar answered Sep 22 '22 22:09

yincrash