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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:27:18+00:00 2026-06-14T15:27:18+00:00

I mean, in which function should i use a text watcher? I’ve tried to

  • 0

I mean, in which function should i use a text watcher?
I’ve tried to use it in the onResume() function, but that didn’t work.

I’m trying to check one of each characters entered in my EditText box while the user is typing. More specifically, I gave the user a riddle and the answer is ‘SOS’. The answer goes in the EditText box and I want to check each character right after its input (I’ve added a max length attribute to the edittext box so it won’t exceed 3). When I find a wrong character, i want to set an X icon image visible, and the opposite if the character is correct.

Here is my TextWatcher code snippet:

final EditText editText=(EditText)findViewById(R.id.editTxt_three);
    editText.addTextChangedListener(new TextWatcher() 
    {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) 
        {

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

        }
        @Override
        public void afterTextChanged(Editable s) 
        {
            for(int i=0;i<editText.length();i++)
            {
                if(i==0)
                {
                    img=(ImageView)findViewById(R.id.icon1);
                    if(s.charAt(i)!='s' || s.charAt(i)!='S')
                        img.setVisibility(1);
                    else
                        img.setVisibility(0);
                }
                if(i==1)
                {
                    img=(ImageView)findViewById(R.id.icon2);
                    if(s.charAt(i)!='o' || s.charAt(i)!='O')
                        img.setVisibility(1);
                    else
                        img.setVisibility(0);
                }
                if(i==2)
                {
                    img=(ImageView)findViewById(R.id.icon3);
                    if(s.charAt(i)!='s' || s.charAt(i)!='S')
                        img.setVisibility(1);
                    else
                        img.setVisibility(0);
                }
            }

        }
    });

In short, where should i use this code?
Feel free to simplify my code if you think of something 🙂

  • 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-14T15:27:19+00:00Added an answer on June 14, 2026 at 3:27 pm

    You can use textwatcher in onCreate, the codes below helps you i think .

    import android.os.Bundle;
    import android.app.Activity;
    import android.text.Editable;
    import android.text.TextWatcher;
    import android.widget.EditText;
    import android.widget.ImageView;
    
    public class MainActivity extends Activity {
        ImageView img,img2,img3;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            final EditText editText=(EditText)findViewById(R.id.editText1);
            editText.addTextChangedListener(new TextWatcher() 
            {
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) 
                {
    
                }
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) 
                {
    
                }
    
                @Override
                public void afterTextChanged(Editable arg0) {
                    String s = editText.getText().toString();
                      for(int i=0;i<editText.getText().toString().length();i++)
                        {
                            if(i==0)
                            {
                                img=(ImageView)findViewById(R.id.imageView1);                           
                                if(s.charAt(i)!='s' || s.charAt(i)!='S')
                                    img.setVisibility(1);
                                else
                                    img.setVisibility(0);
                            }
                            if(i==1)
                            {
                                img2=(ImageView)findViewById(R.id.imageView2);
                                if(s.charAt(i)!='o' || s.charAt(i)!='O')
                                    img2.setVisibility(1);
                                else
                                    img2.setVisibility(0);
                            }
                            if(i==2)
                            {
                                img3=(ImageView)findViewById(R.id.imageView3);
                                if(s.charAt(i)!='s' || s.charAt(i)!='S')
                                    img3.setVisibility(1);
                                else
                                    img3.setVisibility(0);
                            }
                        }
    
                }
            });
        }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use SHA1 function from Linux libraries ( documentation ) which returns
how we can store the e mail id into a database? i mean which
By which I mean a structure with: O(log n) complexity for x.push() operations O(log
I mean we have a class which is already loaded in JVM. and in
which open source software options exist for generating terminal graphics? I mean, there is
How do I know which is the current folder of an App? I mean...
I want to average some .jpg images which are corrupted by zero-mean Gaussian additive
I'm creating an iPad application which needs a UIPopoverController like this one (I mean,
df <- data.frame(age=c(10,10,20,20,25,25,25),veg=c(0,1,0,1,1,0,1)) g=ggplot(data=df,aes(x=age,y=veg)) g=g+stat_summary(fun.y=mean,geom=point) Points reflect mean of veg at each age, which
Okay, some Guys will know what i mean and edit my Question but they

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.