jettimadhuChowdary jettimadhuChowdary - 1 month ago 6
Android Question

how to know key presses in edittext

I need to detect every key press on either a soft or hard keyboard in EditText. I just need to send the characters one at a time as they are pressed and don't need the final text string.

I have tried using an edittext with onkeypress, but ran into the problems here with not getting key presses with soft keyboards. and textwatcher isn't a good option because i need each key press.
Is there any solution to know all the keypresses (including back,shift ,enter.. also)

Answer

if You have EditText then you can used TextWatcher interface.In my code search_edit is 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                          

                    }
                });