How to know key presses in EditText

Implement this:

 et_code_1.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_ENTER) {
                    /* do something */
                }
            return true;
            }
        });

Update:

As you would like to implement a Soft key listener, you can implement TextWatcher. Here is an example: How to use the TextWatcher class in Android?


If you have an EditText, then you can use the TextWatcher interface. In my code, search_edit is an EditText.

search_edit.addTextChangedListener(new TextWatcher() {          
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {                                   
        //here is your code
        myadapter.getFilter().filter(s);
        listview.setAdapter(myadapter); 
    }                       
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        // TODO Auto-generated method stub                          
    }                       
    @Override
    public void afterTextChanged(Editable s) {
        // TODO Auto-generated method stub                  
    }
});

Use addTextChangedListener(TextWatcher watcher) and implement TextWatcher interfaace.