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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:10:41+00:00 2026-06-19T02:10:41+00:00

I am new to Android development (I’m taking a class), so bear with me.

  • 0

I am new to Android development (I’m taking a class), so bear with me.

I have to use a TextWatcher to display edited text from an EditText widget into a TextView widget.

For example, if what was initially typed is edited (like if the user typed “Hoozledoofer” and then highlighted “zledoof” and finally typed “v” in its place), I would have to output the change first in the format:

'zledoof' => 'v'

This is shown on the first line of the TextView. Then, the second line would show the full text now present in the EditText widget:

Hoover

I’m not sure how to do this. I know I need to output the results in the afterTextChanged method. How do I save what was done, and still keep it outputting whatever is typed? Any advice?

Below is a TextWatcher example given in class:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    txtEdit = (EditText) findViewById(R.id.editText1);
    viewText = (TextView) findViewById(R.id.text);

     txtEdit.addTextChangedListener (new TextWatcher() {

          public void beforeTextChanged(CharSequence s, int start, int count, int after) {
              Log.i("TC", "beforeTC " + s.toString() + " "
                      + s.subSequence(start, start + count).toString());
          }

          public void onTextChanged(CharSequence s, int start, int before, int count) {
              Log.i("TC", "onTC " + s.toString() + " "
                      + s.subSequence(start, start + count).toString());
          }

          public void afterTextChanged(Editable s) {
              Log.i("TC", "afterTC " + s.toString());
          }
     });
}

Here’s what I’ve tried which provides the intended final result, but it does keep on showing every little edit made. This may not be an issue and may work for the professor:

     txtEdit.addTextChangedListener (new TextWatcher() {

         String changed, newStr, edit;

          public void beforeTextChanged(CharSequence s, int start, int count, int after) {
              changed = s.subSequence(start, start + count).toString();

              //Log.i("TC", "beforeTC " + s.toString() + " "
                      //+ s.subSequence(start, start + count).toString());
          }

          public void onTextChanged(CharSequence s, int start, int before, int count) {
              newStr = s.toString();
              edit = s.subSequence(start, start + count).toString();

              //Log.i("TC", "onTC " + s.toString() + " "
                      //+ s.subSequence(start, start + count).toString());
          }

          public void afterTextChanged(Editable s) {
              viewText.setText(changed + " => " + edit + "\n" + newStr);

              //Log.i("TC", "afterTC " + s.toString());

          }
     });
  • 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-19T02:10:42+00:00Added an answer on June 19, 2026 at 2:10 am

    Since this is homework I won’t give you the answer. (Your teacher did much of the busy work by giving you a good example to start with.) But I’ll give you a hint:

    For example, if what was initially typed is edited (like if the user typed “Hoozledoofer” and then highlighted “zledoof” and finally typed “v” in its place), I would have to output the change first in the format: 'zledoof' => 'v' This is shown on the first line of the TextView.

    Pay attention to before and after relative to count. This will help you know when the user is adding or subtracting text.

    The second part is easy and you seem to have the answer already:

    Then, the second line would show the full text now present in the EditText widget: Hoover
    I know I need to output the results in the afterTextChanged method.

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

Sidebar

Related Questions

New to Android development and have decided to use NetBeans 6.9.1 as my IDE.
i am new to android development. I am use the following code to set
I am new to Android development. I have both Windows 7 and Mac OS
I am somewhat new to android development and development in general. I have a
I am new to android development. I have created a popup window which is
I am very new to Android development and Java. Have read around but I'm
Im new to android development. Now im trying to use sqlite db. I created
I am new to Android development. Been recently tried to have my own Facebook
I am new to Android Development. For my project, I need to use REST
I am new to android development and I have been having issues with Force

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.