Se connecter

Validate using the enter key on the keyboard

Validate using the enter key on the keyboard

To validate with the enter key on the keyboard, paste the following code just under the previous function:

editText1.setOnKeyListener(new View.OnKeyListener(){
         public boolean onKey(View v, int keyCode, KeyEvent event)
        {
                if (event.getAction() == KeyEvent.ACTION_DOWN)
                {
                        switch (keyCode)
                        {
                                case KeyEvent.KEYCODE_DPAD_CENTER: 
                                case KeyEvent.KEYCODE_ENTER:
                                        button.performClick(); 
                                        return true;
                                default: break;
                        }
                }
                return false;
        }
});

This code is rather complicated to understand but basically it aims to simulate pressing the button when the user presses the key enter his keyboard, hence the « onKey » function used.

TOUT VOIRAjouter une remarque
VOUS
Ajouter votre commentaire

Chercher un cours

Publicité

FREEDOM SUBSTITUTE | 2015-2019

Si vous souhaitez interagir directement avec notre communauté, rendez-vous sur discord :

https://discord.gg/Hm5gEGA

FREEDOM SUBSTITUTE

100 Utilisateurs en ligne