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 6238149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:09:34+00:00 2026-05-24T11:09:34+00:00

I have 2 editText objecst in my android application. I want write to such

  • 0

I have 2 editText objecst in my android application. I want write to such a logic so that if I type something in textField 1, then same should be replicated in Textfield 2 in runtime and vice-versa.

Example: if i type “a” in field1, field2 will also have “a”. If I type “b” in field2, field should also change to “b”

I am able to achieve the same one way i,e from 1 to 2 or 2 to 1 but not simultaneously. Below is the code I wrote:

final EditText tf1 = (EditText)findViewById(R.id.editText1);
final EditText tf2 = (EditText)findViewById(R.id.editText2);

tf1.setOnFocusChangeListener(new View.OnFocusChangeListener()
{
    public void onFocusChange(View v, boolean hasFocus) 
    {
        if (hasFocus)
        {
           tf1.addTextChangedListener(new TextWatcher()
           {
              public void afterTextChanged(Editable s) {tf2.setText(s);}
           } 
        }
     }  
};

Similar way I wrote another listener for tf2 and set the text in tf1. Kindly help on how can this scenario can be handled

  • 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-05-24T11:09:35+00:00Added an answer on May 24, 2026 at 11:09 am

    Your answer is almost there. The key here is to remove the textChangedListener for either of the EditText fields if it loses focus. Then, keep track of which EditText field currently has the listener, and update the other accordingly. Here’s a simple activity that should accomplish what you’re looking for:

    public class EditTextActivity extends Activity implements TextWatcher {
    
        private EditText mEditText1;
        private EditText mEditText2;
        private int mEditTextWatcherNum = 1;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            mEditText1 = (EditText) findViewById(R.id.editText1);
            mEditText2 = (EditText) findViewById(R.id.editText2);
    
            mEditText1.addTextChangedListener(this);
            mEditText1.setOnFocusChangeListener(new OnFocusChangeListener() {
    
                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    if (hasFocus) {
                        mEditText1.addTextChangedListener(EditTextActivity.this);
                        mEditTextWatcherNum = 1;
    
                    } else {
                        mEditText1.removeTextChangedListener(EditTextActivity.this);
                    }
                }
            });
    
            mEditText2.setOnFocusChangeListener(new OnFocusChangeListener() {
    
                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    if (hasFocus) {
                        mEditText2.addTextChangedListener(EditTextActivity.this);
                        mEditTextWatcherNum = 2;
    
                    } else {
                        mEditText2.removeTextChangedListener(EditTextActivity.this);
                    }
                }
            });
    
    
        }
    
        @Override
        public void afterTextChanged(Editable s) {
            switch (mEditTextWatcherNum) {
            case 1:
                mEditText2.setText(s);
                break;
            case 2:
                mEditText1.setText(s);
                break;
            default:
                break;
            }
    
        }
    
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
                //Do Nothing
    
        }
    
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            //Do Nothing
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried to create a android application that sends a serialzed object from
i have a EditText in android in which i want the user to enter
Basically, I want an EditText in Android where I can have an integer value
I have EditText view in android .. i want when the enters a letter
I have an activity that only has a EditText. I want the soft keyboard
Currently I am working on an Android application that is dynamically creating controls. Everytime
If I have an EditText component on my screen that I have specified inputType=decimal
I have one edittext EditText et1=(EditText)findViewById(R.id.EditText01); when i want to clear edittext i use
Currently I have an edittext field that when the user presses enter it does
I want to have 3 edittext with top and bottom having topleft and topright

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.