在输入的EditText数据和无pressing输入响应 [英] Enter data in EditText and respond without pressing enter

查看:140
本文介绍了在输入的EditText数据和无pressing输入响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个听众的EDITTEXT。

I have an editText with a listener.

edittext.setOnKeyListener(new OnKeyListener() {
    public boolean onKey(View v, int keyCode, KeyEvent event)
    {
        // If the event is a key-down event on the "enter" button
        if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
            (keyCode == KeyEvent.KEYCODE_ENTER)) {

            // Perform action on key press
            return true;
        }
        return false;
    }
});

现在我想用我的程序用户在文本框中输入的数据,而用户pressing进入。 (如果我删除(键code == KeyEvent.KEY code_ENTER)然后程序挂起由于某种原因)。

Now I want to use the data entered in the textBox by the user in my program without the user pressing enter. (If I remove (keyCode == KeyEvent.KEYCODE_ENTER) then the program hangs for some reason).

我应该怎么做,以确定用户输入在文本框中一些人物?

What should I do to identify that the user has entered some character in the textbox?

推荐答案

我想你想实现像每当用户输入要检查的任何字符,如果是这种情况的功能,然后有一个的 TextWatcher 为你的类。在这您可以覆盖其3种方法: afterTextChanged beforeTextChanged onTextChanged

I think you want to implement functionality like whenever user enter any character you want to check , if this is the case then there is a TextWatcher class for you. In which you can override its 3 methods: afterTextChanged, beforeTextChanged and onTextChanged.

mPasswordLength = (EditText)findViewById(R.id.password_length);
mPasswordLength.addTextChangedListener(new TextWatcher() {
    public void afterTextChanged(Editable s) {
    }
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    }
    public void onTextChanged(CharSequence s, int start, int before, int count) {
    }
});

这篇关于在输入的EditText数据和无pressing输入响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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