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
Implement this:
myEditText.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_ENTER) {
/* do something */
}
}
});
As you would like to implement Soft key listener, you can implement TextWatcher. Here is example: How to use the TextWatcher class in Android?
Use addTextChangedListener(TextWatcher watcher) and implement TextWatcher interfaace.
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
}
});