ndroid的setOnEditorActionListener

ndroid的setOnEditorActionListener

本文介绍了Android的setOnEditorActionListener()不火的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想设置一个监听器的EditText 时输入按钮将pressed.But它不火的。我与Android 4.2.2测试这对LG的Nexus 4。 setOnEditorActionListener 适用于亚马逊Kindle Fire采用Android 2.3和 setImeActionLabel 作品无处!我也不能为文本输入 button.Here为code:

I'm trying to set a listener to EditText when enter button will be pressed.But it didn't fire at all. I tested this on LG Nexus 4 with Android 4.2.2. setOnEditorActionListener works on Amazon Kindle Fire with Android 2.3 and setImeActionLabel works nowhere! I also can't set text for Enter button.Here is code:

mEditText.setImeActionLabel("Reply", EditorInfo.IME_ACTION_UNSPECIFIED);
mEditText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId,
                KeyEvent event) {
            Log.d("TEST RESPONSE", "Action ID = " + actionId + "KeyEvent = " + event);
            return true;
        }
    });

我是什么做错了吗?我该如何解决这个问题?

What am I doing wrong? How can I fix this?

推荐答案

您可以使用的。

    editText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.charAt(s.length() - 1) == '\n') {
                  Log.d("TEST RESPONSE", "Enter was pressed");
            }
        }
    });

这篇关于Android的setOnEditorActionListener()不火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 14:59