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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:36:48+00:00 2026-06-12T00:36:48+00:00

I am working on an Android application. In my app I am facing a

  • 0

I am working on an Android application. In my app I am facing a strange problem.Please have a look on my screen.enter image description here

when i select any thing from selction box then it will add twice to the edittext.

the following is my code for edittext

snd_txt.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub
            System.out.println("onTextChanged"+start+"b4"+before+"count"+count);
            if (start>0) {

                    int m=snd_txt.getText().toString().lastIndexOf(".");
                    makeColorText(m,snd_txt.getText().toString().length());

            }
        }

        @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

        }
    });




public void makeColorText(int num,int last) {

    int start=last-44;
    if (start<1){
        start=0;
    }
     SpannableString ss = new SpannableString(snd_txt.getText());

     ss.setSpan(new ForegroundColorSpan(R.color.Gray_Light), 0, start,0);
     ss.setSpan(new ForegroundColorSpan(Color.BLACK), start, last, 0); 
    // customize ss here
    // ...



    snd_txt.setText(ss);
    snd_txt.setSelection(last);
}

If i comment the snd_txt.setText(ss); statement .the the edittext will work perfectly. But I can’t do that.I used that method to change edittext color at runtime. working fine for all the time..But at the time of selecting predictions will add the word two times.

Anybody have any idea to solve, Please help me.

Edit: How can I create a custom edittext with multicolor text.. for eg: current line in blue and previous are black.something like that

  • 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-12T00:36:49+00:00Added an answer on June 12, 2026 at 12:36 am

    Solved my problem by changing my code.

    snd_txt.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // TODO Auto-generated method stub
                if (start>0) {
                     int m=snd_txt.getText().toString().lastIndexOf(".");
             makeColorText(snd_txt.getText().toString().length(),count);    
                }
            }
    
            @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
            }
        });
    
    public void makeColorText(int last,int count) {
    
        int start=last-44;
        if (start<1){
            start=0;
        }
    
        String s=snd_txt.getText().toString();
    
        if (count==before_val&count!=1) {
    
            s=s.substring(0, last-before_val);
            last=last-before_val;
        }
    
         SpannableString ss = new SpannableString(s);
    
         ss.setSpan(new ForegroundColorSpan(R.color.Gray_Light), 0, start,0);
         ss.setSpan(new ForegroundColorSpan(Color.BLACK), start, last, 0); 
        // customize ss here
        // ...
    
    
    
             snd_txt.setText(ss);
    
    
         before_val=count;
    
    
        snd_txt.setSelection(last);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on android chat application. I am facing a problem in send
I am working on an Android application.In my app I have to use images
I have the following problem: I am working on an Android application where at
I am working with an Android application. In my app I have to change
I am working on a new android application.In my app i have to add
Our team is working on Android Application back ended with App Engine. We have
Now I am working on a Android application. In my app i have to
I am working on an ANdroid application.In my app I have to list all
I am working on an Android application.In my app I have change the textview
I'm working with FlashBuilder 4.6 to develop Android app. In the application there is

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.