0

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) { }
plaes
  • 31,788
  • 11
  • 91
  • 89
  • 1
    http://stackoverflow.com/questions/7962704/how-to-support-arabic-text-in-android – Stephan Branczyk Mar 29 '13 at 07:57
  • thanks 4 ur answer , but my problem no in support arabic , I am Use android 4, but my problem in handle some event key like B or A , it not work with any char , just type char it – محمد احمد الجبوري Mar 29 '13 at 14:01
  • Sorry, I did not read your question carefully enough. You need two equal signs instead of one equal sign in your comparison: keyCode == KeyEvent.KEYCODE_5 (instead of keyCode = KeyEvent.KEYCODE_5) – Stephan Branczyk Mar 29 '13 at 16:36
  • I did that and when I put my code her forget (==), but my problem not with numeric key so only with alpha key like (A,B,C...), that key I can not handle event it, and I put this issue in more one but no body solved it, please follow my problem – محمد احمد الجبوري Mar 30 '13 at 07:14
  • Your question should have never been closed since it wasn't a duplicate. I'd suggest you repost your question again as a new question, but excluding everything related to the arabic language (and not mentioning the previous question either). Things will look simpler if you take out the arabic font from your problem and reduce the problem to its bare essential issue. Also, please post only one version of the code you've tried, its last version, not multiple versions. Recalling a version of the code you wrote from your own personal human memory is too error-prone to be of any use. – Stephan Branczyk Mar 30 '13 at 08:47

0 Answers0