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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:04:13+00:00 2026-06-17T13:04:13+00:00

I’ve made a very simple Android activity: public class SimpleActivity extends Activity { private

  • 0

I’ve made a very simple Android activity:

public class SimpleActivity extends Activity {

private EditText editText1;
private EditText editText2;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    LinearLayout verticalLayout = new LinearLayout(this);
    verticalLayout.setOrientation(LinearLayout.VERTICAL);
    editText1 = new EditText(this) {
        @Override
        protected void onTextChanged(CharSequence text, int start,
                int lengthBefore, int lengthAfter) {
            // TODO Auto-generated method stub
            super.onTextChanged(text, start, lengthBefore, lengthAfter);
        }
    };
    editText1.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            System.out.println(s.toString());
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub

        }
    });
    editText1.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
    verticalLayout.addView(editText1);
    editText2 = new EditText(this);
    editText2.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
    verticalLayout.addView(editText2);
    setContentView(verticalLayout);
}

public EditText getEditText1() {
    return editText1;
}

public EditText getEditText2() {
    return editText2;
}

}

When I run this code on my Android device, both overriden EditText.onTextChanged() method & TextWatcher.onTextChanged() methods are called while component is inited. Also they’re correctly called, when I call method editText1.setText(“text”)

When I create SimpleActivity in Roboelectric test runner, it’s created & editText1/editText2 are not null, but EditText.onTextChanged() & TextWatcher.onTextChanged() aren’t called while component init & while calling EditText.setText()
How to make TextWatcher work? It’s importaint part of my application & it can’t be tested without handling text changed events.

Please help.

  • 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-17T13:04:14+00:00Added an answer on June 17, 2026 at 1:04 pm

    Using Robolectric 1.1, I tested this code:

    @RunWith(RobolectricTestRunner.class)
    public class TestSimpleActivity {
    
        @Test
        public void testMethod() {
            SimpleActivity activity = new SimpleActivity();
            activity.onCreate(null);
            activity.getEditText1().setText("hello world");
        }
    
    }
    

    I was able to see the TextWatcher.onTextChanged() fire, but not EditText.onTextChanged(). It’d be ideal if both fired, but take a look at https://github.com/pivotal/robolectric/blob/robolectric-1.1/src/main/java/com/xtremelabs/robolectric/shadows/ShadowTextView.java#L63. It looks like TextWatcher will fire, but onTextChange() doesn’t appear implemented for subclasses.

    If you need that functionality, you’ll have to implement it in Robolectric. Unfortunately, Robolectric has gaps in its implementation.

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

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm making a simple page using Google Maps API 3. My first. One marker
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
Let's say I'm outputting a post title and in our database, it's Hello Y’all
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.