I am trying to design an application to write custom text, where the text is like "محمّدُ ", but I'm unable to write char 'ُ ' using soft keyboard.
I tried to handle keyevent in edittext using this code:
public boolean onKey(View view, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_B || keyCode = KeyEvent.KEYCODE_5) {
editText1.setText("ً");
return true;
}
return false;
}
But when I press on key 5 (or key enter) the text was work corrctly (it occurred "ً") and when I press on key B the text does not work and character "B" is enter in textbox.
Then I tried the way textwacher showed below but eventually ran into same problem
editText1.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
editText1.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode,KeyEvent event) {
// If the event is a key-down event on the "enter" button
if (keyCode == KeyEvent.KEYCODE_M) {
editText1.setText("م");
return true;
}
return false;
}
}
});
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) { }