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

The Archive Base Latest Questions

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

I put this code from answer Displaying emoticons in Android for showing emoticons in

  • 0

I put this code from answer Displaying emoticons in Android for showing emoticons in Edittext but I have a problem when I’m typing a lot of text, it becomes slower and slower and almost impossible to type.
This is the code: How can I make it faster?

 textS.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) {
                addSmiledText(Main.this, s);
               // Log.e("",s.toString());

            }
        });}


     private static final HashMap<String, Integer> emoticons = new HashMap<String, Integer>();
     static {
         emoticons.put(":)", R.drawable.face_smile);
         emoticons.put(":-)", R.drawable.face_smile);
         emoticons.put(":(", R.drawable.face_sad);
         emoticons.put(":-(", R.drawable.face_sad);
         emoticons.put(":-D", R.drawable.face_smile_big);
         emoticons.put(":D", R.drawable.face_smile_big);
         emoticons.put(":lol:", R.drawable.face_laughing);
            emoticons.put("8)", R.drawable.face_cool);
            emoticons.put(";)", R.drawable.face_wink);
           emoticons.put(";-)", R.drawable.face_wink);
            emoticons.put(";(", R.drawable.face_crying);
           ...

     }
     public static Spannable addSmiledText(Context ch, Editable s) {

            int index;
            for (index = 0; index < s.length(); index++) {
                for (Entry<String, Integer> entry : emoticons.entrySet()) {
                    int length = entry.getKey().length();
                    if (index + length > s.length())
                        continue;
                    if (s.subSequence(index, index + length).toString().equals(entry.getKey())) {
                        s.setSpan(new ImageSpan(ch, entry.getValue()), index, index + length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                        index += length - 1;
                        break;
                    }
                }
            }
            return s;
        }
  • 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:26:25+00:00Added an answer on June 12, 2026 at 12:26 am

    how to make it to scan only two last characters?

    You have:

    for (index = 0; index < s.length(); index++)
    

    If you do not want to scan the entire string each time, choose a better starting value for index.

    For example, since your minimum-length emoticon has two characters and your maximum-length emoticon has five characters, skip the loop entirely for Editable objects of length 0 or 1, and then have index start at s.length()-5.

    Note, though, that afterTextChanged() is not only called for changes at the end. The user might have repositioned the cursor to be somewhere in the middle. Hence, you really should be scanning in onTextChanged() and looking at the window of text around the point of the change.

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

Sidebar

Related Questions

I have this code in Android: Map<String, String> idObject1 = new LinkedHashMap<String, String>(); idObject1.put(Id,
[Rails] Where to put this code? I have a user1 and when another registered
Okay, I know it is weird but when I put this code between <head
I have this code for update: public Boolean update() { try { data.put(ContactsContract.Groups.SHOULD_SYNC, true);
I have this code that I've edited: http://pastebin.com/vrqHek6S I've put in comments where I
i put a drawable in a EditText with this code: final Drawable x =
I have a code but in this code there is an error and I
I know there is a simple answer but I can't seem to put this
When I put this code in <asp:LoginStatus ID=LoginStatus1 runat=server style=top: 170px; left: 890px; position:
how to put this code below? - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { NSString *year

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.