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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:54:57+00:00 2026-05-31T21:54:57+00:00

during my debug sessions I found a strange thing occurring. I have an EditText

  • 0

during my debug sessions I found a strange thing occurring. I have an EditText control for which I defined the current activity as OnKeyListener to perform validation while user types.

Code

txtPhoneNumber.setOnEditorActionListener(this);
txtPhoneNumber.setOnKeyListener(this);
txtPhoneNumber.setOnFocusChangeListener(this);

@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    String phoneNumber = ((TextView) v).getText().toString();
    if (phoneNumber != null && !"".equals(phoneNumber))
        setValidPhoneNumber(checkValidPhoneNumber(phoneNumber));

    setForwardButtonEnabled(this.validPhoneNumber && this.readyToGo);

    if (actionId == EditorInfo.IME_ACTION_DONE) {
        InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        in.hideSoftInputFromWindow(v.getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }

    return false;
}

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {

    String phoneNumber = ((TextView) v).getText().toString();
    if (phoneNumber != null && !"".equals(phoneNumber))
        setValidPhoneNumber(checkValidPhoneNumber(phoneNumber));

    setForwardButtonEnabled(this.validPhoneNumber && this.readyToGo);

    return false;
}

OK I can admit that this is quite redundant to perform validation again when the user is pressing the Enter key, more than just closing the soft keyboard. However I found that the OnKey event is dispatched twice.

For example I’m writing 3551234567 and I already typed 355. When I press 1, one event is fired having v.getText() = 355 and next another event has v.getText() = 3551.

I would like to know if this is normal and if this can be avoided by either distinguishing if this is a “preOnKeyEvent” or “postOnKeyEvent”. I only need the string after the event, not before.

Thank you

  • 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-31T21:54:58+00:00Added an answer on May 31, 2026 at 9:54 pm

    You are probably getting both the key down/key up events.

    Try filtering your method by checking the action of the KeyEvent for an ACTION_UP action.

    Read this for more information

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

Sidebar

Related Questions

Is there a way to vizualise the activity stack, at some moment during debug,
During my apprenticeship, I have used NHibernate for some smaller projects which I mostly
I have a question about the login control of asp.net. I defined on my
I am currently working on a simulator and encountered the following error during debug
I'm trying do build and debug a small project for BlackBerry. During the build
During debug builds I would like to show the duration it took, server side,
Short During debug process I see that, all goes right. For debugging purposes, before
In Visual studio when an error happens during debug, the line causing the error
how to change background color of line highlighting during debug process in Netbeans? Tried
Do you know a way to add some code that, during debug , programmatically

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.