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

  • Home
  • SEARCH
  • 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 6371633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:06:14+00:00 2026-05-25T01:06:14+00:00

I want to create an application that can transform text the user enters in

  • 0

I want to create an application that can transform text the user enters in an EditText widget in real time, and I’ve added a TextWatcher to allow me to do stuff on text change, but it’s causing an overflow error because I’m basically creating an endless loop (onTextChange -> code to change text -> onTextChange -> etc...).

Anyone got an idea on how to get around this issue?

Here’s an example

private boolean isEditable = true;
private EditText text;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    text = (EditText) findViewById(R.id.editText1);
    text.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
        }

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

        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            if (isEditable) {
                isEditable = false;
                styleText(s.toString());
            } else {
                isEditable = true;
            }
        }

    });

}

private void styleText(String completeText) {
    text.setText(completeText + " test");
}

And while the above actually seems to be working, I cannot get it to work with Html.fromHtml();, which is what I intend to use.

EDITED AGAIN

public class Main extends Activity implements TextWatcher {

    private EditText text;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        text = (EditText) findViewById(R.id.editText1);
        text.addTextChangedListener(this);
    }

    @Override
    public void afterTextChanged(Editable s) {
        text.removeTextChangedListener(this);
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {
        text.addTextChangedListener(this);
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        text.removeTextChangedListener(this);
        text.setText("Test!");
    }
}

It’s throwing a StackOverflowException on line 37, which is “text.setText("Test!");“

  • 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-25T01:06:14+00:00Added an answer on May 25, 2026 at 1:06 am

    EDIT: And works, no exception is thrown:

      txtwt = new TextWatcher(){
    
                @Override
                public void afterTextChanged(Editable s) {
    
                Log.i("REACHES AFTER", "YES");
    
                }
    
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count,
                        int after) {
                    Log.i("REACHES BEFORE", "YES");
                }
    
                @Override
                public void onTextChanged(CharSequence s, int start, int before,
                        int count) {
                    text.removeTextChangedListener(txtwt);//after this line you do the editing code 
                    text.setText("TEST");
                    Log.i("REACHES ON", "YES");
                    text.addTextChangedListener(txtwt); // you register again for listener callbacks
    
                }};
           text = (EditText) findViewById(R.id.editText1);
            text.addTextChangedListener(txtwt);
    

    This is the Logcat proof, when I dramatically pushed keys :

    08-28 19:53:21.265: INFO/REACHES BEFORE(492): YES
    08-28 19:53:21.276: INFO/REACHES ON(492): YES
    08-28 19:53:21.276: INFO/REACHES AFTER(492): YES
    08-28 19:53:21.296: INFO/REACHES BEFORE(492): YES
    08-28 19:53:21.305: INFO/REACHES ON(492): YES
    08-28 19:53:21.305: INFO/REACHES AFTER(492): YES
    08-28 19:53:21.745: INFO/REACHES BEFORE(492): YES
    08-28 19:53:21.755: INFO/REACHES ON(492): YES
    08-28 19:53:21.755: INFO/REACHES AFTER(492): YES
    08-28 19:53:21.775: INFO/REACHES BEFORE(492): YES
    08-28 19:53:21.785: INFO/REACHES ON(492): YES
    08-28 19:53:21.785: INFO/REACHES AFTER(492): YES
    08-28 19:53:22.698: INFO/REACHES BEFORE(492): YES
    08-28 19:53:22.705: INFO/REACHES ON(492): YES
    08-28 19:53:22.705: INFO/REACHES AFTER(492): YES
    08-28 19:53:23.855: INFO/REACHES BEFORE(492): YES
    08-28 19:53:23.865: INFO/REACHES ON(492): YES
    08-28 19:53:23.865: INFO/REACHES AFTER(492): YES
    08-28 19:53:24.385: INFO/REACHES BEFORE(492): YES
    08-28 19:53:24.395: INFO/REACHES ON(492): YES
    08-28 19:53:24.395: INFO/REACHES AFTER(492): YES
    08-28 19:53:24.485: INFO/REACHES BEFORE(492): YES
    08-28 19:53:24.485: INFO/REACHES ON(492): YES
    08-28 19:53:24.485: INFO/REACHES AFTER(492): YES
    08-28 19:53:24.515: INFO/REACHES BEFORE(492): YES
    08-28 19:53:24.525: INFO/REACHES ON(492): YES
    08-28 19:53:24.525: INFO/REACHES AFTER(492): YES
    08-28 19:53:24.625: INFO/REACHES BEFORE(492): YES
    08-28 19:53:24.635: INFO/REACHES ON(492): YES
    08-28 19:53:24.635: INFO/REACHES AFTER(492): YES
    08-28 19:53:24.654: INFO/REACHES BEFORE(492): YES
    08-28 19:53:24.665: INFO/REACHES ON(492): YES
    08-28 19:53:24.665: INFO/REACHES AFTER(492): YES
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a c# application with multiple windows that are all transparent
I want to know if i can create a custom google maps application,on which
I want to create a timesheet application where I need an application that will
I want to know how to write a C# desktop application that can connect
I want to create an objective c application that interprets a list of .aiml
I want to run javascript/Python/Ruby inside my application. I have an application that creates
I want to create an application which will have a client and server components.
I want to create a Java application bundle for Mac without using Mac. According
I want to create my Rails application with MySQL, because I like it so
Say I want to create vb.net application in Visual studio 2005. What is the

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.