I’m trying to implement iPhone like PIN-code authorization with 4 EditText blocks like this:

I’m using TextWatcher to check if field was changed so I can jump between blocks.
Here is the code:
@Override
public void afterTextChanged(Editable s) {
if (del && index > 0) {
pin[index - 1].requestFocus();
}
else if ( ! del && ind < 3) {
pin[index + 1].requestFocus();
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
del = count != 0;
}
Everything works fine except when block is empty and DEL/BACKSPACE is pressed, I want to go back to previous block and clear its’ value.
This is where TextWatcher fails me since no change was made in empty block it doesn’t do anything.
I have tried using keyEventListener but it only catches events on emulator not on actual device via virtual keyboard.
Can anyone suggest an idea of how can I catch DEL event or any other way to implement this?
I found a workaround for this issue. This is probably not the best solution, but it works for me.
Aside from
TextWatcherI’ve addedInputFilterto blocksI also think it’s a better idea to port the rest of the code from
TextWatchertoInputFilter