OnEditorActionListener不工作 [英] OnEditorActionListener not working

查看:470
本文介绍了OnEditorActionListener不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想捕捉事件时的一个EditText用户preSS进入。

I simply want to catch the event when the user press enter on an editText.

我没有得到敬酒消息,而不是输入pressed,而不是一些关键pressed!无论是。

I did not get the Toast message, not the "Enter pressed" and not the "Some key pressed!" either.

什么M我做错了吗?

myEditText.setOnEditorActionListener(new OnEditorActionListener() {

    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

   Toast.makeText(getApplicationContext(), "Some key pressed!", Toast.LENGTH_LONG).show();

        if (event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
             Toast.makeText(getApplicationContext(), "Enter pressed", Toast.LENGTH_LONG).show();
                return true;
                }
                return false;
            }
        });

E D I T:

E D I T :

那么它正在开发的Andr​​oid 2.3.3,而不是工作4.1.2 任何想法我如何使这项工作在任何Android设备?

Well it is working on Android 2.3.3 and not working on 4.1.2 Any ideas how can i make this work on any android device?

推荐答案

请尝试设置的EditText在单行模式。 txtEdt.setSingleLine(); 或在布局文件: 机器人:单线=真正的

Please try to set the EditText in single-line mode. txtEdt.setSingleLine(); or in layout file: android:singleLine="true"

这篇关于OnEditorActionListener不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆