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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:48:29+00:00 2026-06-13T02:48:29+00:00

Every time I pressed enter the toast keeps popping out even if it should

  • 0

Every time I pressed enter the toast keeps popping out even if it should not come out…

take a lot at my code:

etAddMove.setOnKeyListener(new OnKeyListener() {

            @SuppressLint("NewApi")
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // TODO Auto-generated method stub
                if(keyCode == KeyEvent.KEYCODE_ENTER && event.getRepeatCount() == 0){
                    String ssmoveName = etAddMove.getText().toString();
                    int x = ssmoveName.length() - 1;
                    if (ssmoveName.isEmpty() || Character.isWhitespace(ssmoveName.charAt(0)) || Character.isWhitespace(ssmoveName.charAt(x))) {
                        Toast.makeText(ListMovingNames.this, 
                                "Please enter a valid name! Avoid giving a blank name or white space at the beginning or end of the name", 
                                Toast.LENGTH_LONG).show();
                    }else{
                        try {
                            SQLHandler check = new SQLHandler(ListMovingNames.this);
                            check.open();
                            String scheck = check.checkMove(ssmoveName);
                            check.close();
                            if (!scheck.equals(ssmoveName)) {
                                Toast.makeText(ListMovingNames.this, "Move name already exist please give a different name", Toast.LENGTH_LONG).show();
                            } else{
                                SQLHandler entry = new SQLHandler(ListMovingNames.this);
                                entry.open();
                                entry.createMove(ssmoveName);
                                entry.setTodo(ssmoveName);
                                entry.close();
                                Intent i = new Intent(getApplicationContext(), StartMoving.class);
                                i.putExtra("moveName", ssmoveName);
                                startActivity(i);
                            }
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            SQLHandler entry = new SQLHandler(ListMovingNames.this);
                            entry.open();
                            entry.createMove(ssmoveName);
                            entry.setTodo(ssmoveName);
                            entry.close();
                            Intent i = new Intent(getApplicationContext(), StartMoving.class);
                            i.putExtra("moveName", ssmoveName);
                            startActivity(i);
                        }
                    }
                    return true;
                }

                return onKeyDown(keyCode, event);
            }
        });

how can you make this guy stop if I don’t want it to show…

EDIT

I think I know why this is happening, It must be because each time i press enter keyup and keydown is initialize thats why the first initialization is keydown which calls the condition and returns false and when keydown is called the condition is called again which will return true, making the toast display. thats what i think so far…

  • 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-13T02:48:30+00:00Added an answer on June 13, 2026 at 2:48 am

    Finally solve this shit. As I was suspecting the reason why toast keeps showing is that everytime the enter key is press, the keydown and keyup is called that’s why the process is called twice making the toast appear because the condition to show the toast is meet when the process is called the second time.

    So to avoid that KeyEvent.ACTION_DOWN must be present.

    public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // TODO Auto-generated method stub
                    if ( (event.getAction() == KeyEvent.ACTION_DOWN  ) && (keyCode== KeyEvent.KEYCODE_ENTER)   )
                    {               
                        // do something here
                        }
                        return true;
                    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Every time I run the code below it is supposed to come up with
Every time enter is pressed the entire page refreshes on the iPad, I want
Currently the sprite only moves one pixel every time a key is pressed. How
Every time i reset & seed my database it wipes out the standard admin@example.com
I have a IBAction UILabel to add a number every time it is pressed.
How can I toggle an event every time F2 is pressed by the user?
I have one android activity which extends ListActivity. Every time list items is pressed
Currently, it seems that every time Ctrl-C is pressed within a textbox to copy
Every time when I'm trying to load the .dll in my application, I'm getting
every time I open my Solution in Visual Studio it tries to communicate and

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.