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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:18:23+00:00 2026-05-30T12:18:23+00:00

I need to detect text changes in an EditText. I’ve tried TextWatcher, but it

  • 0

I need to detect text changes in an EditText. I’ve tried TextWatcher, but it doesn’t work in a way I would expect it to. Take the onTextChanged method:

public void onTextChanged( CharSequence s, int start, int before, int count )

Say I have the text “John” in already in the EditText. If press another key, “e”, s will be “Johne”, start will be 0, before will be 4, and count will be 5. The way I would expect this method to work would be the difference between what the EditText previously was, and what it’s about to become.

So I would expect:

s = "Johne"
start = 4 // inserting character at index = 4
before = 0 // adding a character, so there was nothing there before
count = 1 // inserting one character

I need to be able to detect individual changes every time a key is pressed. So if I have text “John”, I need to know “e” was added at index 4. If I backspace “e”, I need to know “e” was removed from index 4. If I put the cursor after “J” and backspace, I need to know “J” was removed from index 0. If I put a “G” where “J” was, I want to know “G” replaced “J” at index 0.

How can I achieve this? I can’t think of a reliable way to do this.

  • 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-30T12:18:24+00:00Added an answer on May 30, 2026 at 12:18 pm

    Use a textwatcher and do the diff yourself. store the previous text inside the watcher, and then compare the previous text to whatever sequence you get onTextChanged. Since onTextChanged is fired after every character, you know your previous text and the given text will differ by at most one letter, which should make it simple to figure out what letter was added or removed where. ie:

    new TextWatcher(){ 
        String previousText = theEditText.getText();
    
        @Override 
        onTextChanged(CharSequence s, int start, int before, int count){
            compare(s, previousText); //compare and do whatever you need to do
            previousText = s;
        }
    
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to use JQuery in order to detect the changes on a text
I need to detect Image format to save a image like image1.jpg, image2.gif, but
I need to detect if text input was processed by keyboard or some auto
I need to find a fairly efficient way to detect syllables in a word.
How can I detect any text changes in a textField? The delegate method shouldChangeCharactersInRange
I'm getting in trouble by hooking window messages. I need to detect window text
Is there is any way to detect text box value changed , whether users
I need to detect when a session has expired in my Visuial Basic web
I need to detect whether my application is running within a virtualized OS instance
I need to detect whether my Makefile is running under valgrind (indirectly, using valgrind

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.