Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8632915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:25:01+00:00 2026-06-12T09:25:01+00:00

I have an activity with 20 EditTexts on it. I want to display a

  • 0

I have an activity with 20 EditTexts on it. I want to display a message if anything has been entered. Instead of attaching 20 listeners to each field, is there a way to know if input has been supplied(data changed)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:25:02+00:00Added an answer on June 12, 2026 at 9:25 am

    Here is an example of a base class that takes care of notifying subclasses if any of their EditText widgets is being used(if any exist). Depending on what you want to do when the user inputs something you may need to change my example to suit your particular case.

    Base activity from which you’ll inherit:

    public abstract class BaseTextWatcherActivity extends Activity {
    
        private TextWatcher mInputObserver = new TextWatcher() {
    
            @Override
            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
            }
    
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
            }
    
            @Override
            public void afterTextChanged(Editable s) {
                onInputChange(s.toString());
            }
        };
        private boolean mOptimize = false; 
    
        @Override
        public void setContentView(int layoutResID) {
            View content = getLayoutInflater().inflate(layoutResID, null);
            initInputsObservers((ViewGroup) content);
            mOptimize = true;
            super.setContentView(content);
        }
    
        @Override
        public void setContentView(View view) {
            if (view instanceof EditText) {
                ((EditText) view).addTextChangedListener(mInputObserver);
            } else if (view instanceof ViewGroup && !mOptimize) {
                initInputsObservers((ViewGroup) view);
                mOptimize = false;
            }
            super.setContentView(view);
        }
    
        /**
         * Implement this method to allow your activities to get notified when one
         * of their {@link EditText} widgets receives input from the user.
         * 
         * @param s the string that was entered by the user in one of the EditTexts.
         */
        public abstract void onInputChange(String s);
    
        /**
         * This will recursively go through the entire content view and add a
         * {@link TextWatcher} to every EditText widget found.
         * 
         * @param root
         *            the content view
         */
        private void initInputsObservers(ViewGroup root) {
            final int count = root.getChildCount();
            for (int i = 0; i < count; i++) {
                final View child = root.getChildAt(i);
                if (child instanceof EditText) {
                    ((EditText) child).addTextChangedListener(mInputObserver);
                } else if (child instanceof ViewGroup) {
                    initInputsObservers((ViewGroup) child);
                }
            }
        }
    
    }
    

    Then all you have to do in your activities is implement the onInputchange callback to let you know that the user entered something in one of the EditTexts from the current layout. You may want to look at the key event callbacks from the activity class for something simpler, but if I’m not mistaken those events are consumed by the TextView/EditText widgets.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My app has 4-5 EditTexts on each activity and I have 10 or so
I have an activity that only has a EditText. I want the soft keyboard
I have this EditText field inside of one activity, and I want it so
I have an activity that contains several user editable items (an EditText field, RatingBar,
in my app i have activity with XML layout, i want to build an
I have created this simple android Activity to demonstrate my problem. I just want
I have 5 editTexts and 2 buttons for each editText so 10 of them.
I have an simple EditText inside an Activity and I want to create a
I have one activity Select which has four buttons and other activity Result. Now
I have an activity setup with an edittext field and an add button. Essentially

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.