android: Softkeyboard realizar acción cuando se presiona la tecla Done


Tengo un EditText. Quiero que después de escribir algo de texto, cuando el usuario presiona la tecla Done de softkeybard, debe realizar alguna operación de búsqueda que también he implementado en un evento de clic de botón. Cómo hacer eso...???

Author: Khawar Raza, 2011-09-28

4 answers

Prueba esto

editText.setOnEditorActionListener(new OnEditorActionListener() {        
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if(actionId==EditorInfo.IME_ACTION_DONE){
            //do something
        }
    return false;
    }
});
 160
Author: Adil Soomro,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-09-28 13:38:50

Prueba esto

Funciona tanto para DONEcomo para RETURN.

EditText editText= (EditText) findViewById(R.id.editText);
editText.setOnEditorActionListener(new EditText.OnEditorActionListener() {

                @Override
                public boolean onEditorAction(TextView v, int actionId,
                        KeyEvent event) {
                    if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER
                            || actionId == EditorInfo.IME_ACTION_DONE) {
                        // Do your action
                        return true;
                    }
                    return false;
                }
            });
 18
Author: Silambarasan Poonguti,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-10-24 14:24:34

Coges el KeyEvent y luego compruebas su código. FLAG_EDITOR_ACTION se utiliza para identificar las claves de entrada que provienen de un IME cuya clave de entrada se ha etiquetado automáticamente como "siguiente" o "hecho"

if (event.getKeyCode() == KeyEvent.FLAG_EDITOR_ACTION)
    //your code here

Encuentra los documentos aquí.

Segundo Método

myEditText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
    int result = actionId & EditorInfo.IME_MASK_ACTION;
    switch(result) {
    case EditorInfo.IME_ACTION_DONE:
        // done stuff
        break;
    case EditorInfo.IME_ACTION_NEXT:
        // next stuff
        break;
    }
 }
});
 0
Author: Xar E Ahmer,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-06-17 07:01:34

Prueba esto

Esto funcionará en ambas condiciones, ya sea que su teclado muestre el signo enter o el siguiente signo de flecha

YourEdittextName.setOnEditorActionListener(new TextView.OnEditorActionListener()
    {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
        {
            if(actionId== EditorInfo.IME_ACTION_DONE||actionId==EditorInfo.IME_ACTION_NEXT)
            {
                //Perform Action here 
            }
            return false;
        }
    });

Si u r frente a la línea roja entonces hacer esto... importar Keyevent y EditorInfo pulsando alt + intro entonces todos los errores lo eliminarán correctamente.......

 0
Author: Sunil,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-09 07:00:10