Tags down


How to access view in addTextChangedListener?

By : user2174802
Date : October 17 2020, 08:10 AM
To fix the issue you can do I want to add a method where passing view as parameter below is the code on directly adding somemethod(view) shows error.
code :
private class MyTextWatcher implements TextWatcher {

    private View view;

    private MyTextWatcher(View view) {
        this.view = view;

    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        //access view

    public void onTextChanged(CharSequence s, int start, int before, int count) {
        //access view

    public void afterTextChanged(Editable s) {
        //access view
editText.addTextChangedListener(new MyTextWatcher(editText));

Share : facebook icon twitter icon

Unable to update View in addTextChangedListener()

By : Java
Date : March 29 2020, 07:55 AM
hope this fix your issue I am trying to edit the background of a Button depending on the length of text in EditText. If the length of text is 0 then the background should be translucent else it should be opaque. However, I am not able to update the Button's background dynamically. If I tap somewhere else on the screen then the button's background is updated, but not in real time. , Please do this call after setting the value
code :
    public void onTextChanged(CharSequence s, int start, int before,
            int count) {




Set addTextChangedListener in a function Android

By : MickyS
Date : March 29 2020, 07:55 AM
Does that help You should create a Listener class like so, Just modify the parameters in the constructor to accept the EditText ID you want to add a listener to.
code :
public class addListenerOnTextChange implements TextWatcher {
    private Context mContext;
    EditTextView mEdittextview;

    public addListenerOnTextChange(Context context, EditTextView edittextview) {
        this.mContext = context;
        this.mEdittextview= edittextview;

    public void afterTextChanged(Editable s) {  

    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {

    public void onTextChanged(CharSequence s, int start, int before, int count) {
        //What you want to do
mobileNumber2.addTextChangedListener(new addListenerOnTextChange(this, mobileNumber2));

Using addTextChangedListener gives NullPointerException

By : user3810243
Date : March 29 2020, 07:55 AM
With these it helps Your Edit TextID is incorrect:
EditText searchText=(EditText)rootview.findViewById(R.id.search_bar);

addTextChangedListener cannot be resolved

By : cezstro
Date : March 29 2020, 07:55 AM
hop of those help? Your variable name is of type String. String doesn't have a addTextChangedListener() method.
I suppose you should add the listener to one of your edit text, most probably editName.

Specify addTextChangedListener in XML

By : user4741511
Date : March 29 2020, 07:55 AM
Hope that helps 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}"
Related Posts Related Posts :
  • How to remove Specific activity/activities from activity stack based on some action?
  • How to address "Remediation for JavaScript Interface Injection Vulnerability"?
  • Function returned undefined, expected Promise or value. although i am returning snapshot.val();
  • How to check if new added item exist in recyclerView?
  • How to reconstruct 33-byte compressed NIST P-256 public key from 33 bytes?
  • Error: could not find com.google.gms:google-services:4.2.0
  • if I update the database by DB Browser, it does not change in my app
  • I want to get two jsonArray from one url by using String Request
  • Receive_SMS Permission issue
  • How to unit test retrofit call?
  • Retrieving Uid's from Firebase Database
  • How to automatically close rewarded video ad in onRewarded method
  • Check if two Location Instances are the same value?
  • How to get the base alphabet of a foreign word and sort them accordingly like in device local contact?
  • http2 doesn't seem to be working with OkHttp3 and retrofit2
  • Failed to resolve: com.google.android:flexbox:1.1.0
  • How to fix Xiaomi specific RemoteServiceException with notification icon?
  • Placing text in the center of a CircularProgressIndicator
  • Calculator that accepts floating point values
  • Bitrise error Could not find com.google.gms:google-services:3.2.1
  • Check if Input is empty doesnt work Kotlin
  • Could not find method compile() for arguments [com.google.gms:google-services:4.0.0]
  • View AGPS setting in Android
  • Am I doing dependency injection in activity code correctly?
  • React Native Gradle ImagePicker wont build
  • React Native changes to code have no affect on emulator app?
  • Get the TextView value of the gridview while clicking on an element
  • How to launch an intent for a third party app?
  • Going crazy trying to change android theme on Xamarin.Forms
  • Could not find any matches for com.android.tools.build:gradle:2.3.+ as no versions of com.android.tools.build:gradle are
  • How can I capture variables inside of Context
  • React Native : Could not find com.android.tools.build:gradle:2.2.3
  • Google Login/Signin on Yandex Android extension
  • Retrofit generates wrong GET request parameters from Map<String : Any>
  • Flutter app crashing when opening first time with ClassNotFoundException on Android
  • Android LinearLayout programmatically one column left, one column float right
  • Kotlin - convert UTC to local time
  • Android'd ForegroundDispatch for NFC
  • How to use Shared Preferences in class to set all activities?
  • Synchronous Volley request locks up
  • How do I inherit a function from another class into an activity in kotlin?
  • BottomAppBar Navigation Icon with Badge
  • Change content_main XML in Basic Navigation Drawer Template
  • HERE SDK Android: PositioningManager not working with NETWORK_PROVIDER in 3.8 or 3.9
  • No response after putting in Header in request
  • Where are default shared preferences written to?
  • how to show a part of next image in daimajia slider?
  • AlertDialog Builder inside holder.itemView.setOnClickListener onBindViewHolder
  • Flutter Grid view is not scrolling
  • How do I link multiple activities in android navigation editor?
  • Failed to resolve: com.google.android.exoplayer:extension-mediasession:2.8.4
  • ViewPager + Picasso + multiple images from URL String array
  • how do I open another fragment after selecting the image in recycler view?
  • Send data from fragment to another fragment
  • Custom TitleView with Description and Preview Image Android TV (FireTV)
  • Gradle project sync failed. basic functionality (e.g. editing debugging) will not work properly
  • how to retrieve firebase storage images in release mode?
  • Android Studio: Could not find matches as no versions of com.android.tools.build:gradle are available
  • Getting a JSON Left side Value
  • Is it possible to use of Mobile data while transferring file via Wi-Fi Direct?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org