Reputation: 21
I am using InputMethodService for my sticker keyboard android application by extending InputMethodService class as below :
public class ImageKeyboard extends InputMethodService {
...
}
The layout for keyboard is created dynamically in my .java file.
There is a backspace button in my keyboard and I have successfully implemented it as below using KEYCODE_DEL as below :
btnDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sendDownAndUpKeyEvent(KeyEvent.KEYCODE_DEL, 1);
}
});
Below is the sendDownAndUpKeyEvent() method you can check :
public void sendDownAndUpKeyEvent(int keyEventCode, int flags) {
sendDownKeyEvent(keyEventCode, flags);
sendUpKeyEvent(keyEventCode, flags);
}
Inner methods are as below :
public void sendDownKeyEvent(int keyEventCode, int flags) {
mInputConnection.sendKeyEvent(
new KeyEvent(
SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(),
KeyEvent.ACTION_DOWN,
keyEventCode,
0,
flags
)
);
}
and
public void sendUpKeyEvent(int keyEventCode, int flags) {
mInputConnection.sendKeyEvent(
new KeyEvent(
SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(),
KeyEvent.ACTION_UP,
keyEventCode,
0,
flags
)
);
}
Now, as I have taken click listener on my btnDelete, only single value gets erased when everytime I press my btnDelete button.
I also have to erase values when user make the button pressed i.e. have to erase multiple values simultaneously.
InShort, BackSpace should work same as back key of device's default keyboard.
Have any idea to handle it ? Thanks.
Upvotes: 2
Views: 70