Disable "Enter key" to start TextWatcher

I made an application to work as a remote keyboard, where the user clicks on edittext, and the type and corresponding alphabets will be entered on the computer.

I detected various letters and numbers using TextWatcher and successfully sent them to my server.

The problem occurs when the user presses the enter key. It also calls TextWatcher. and since I post the last entered changes, the error appears on the server side.

As a solution, I made, also installed one onkeylistener, which will detect the input key and execute the action and CONSUME , but, unfortunately, the first text element and then onkeylistener are also launched in this case.

Here is the code of my onkeylistener

 keyboard.setOnKeyListener(new OnKeyListener() {                 
  public boolean onKey(View v, int keyCode, KeyEvent event) {                   
    if(keyCode == KeyEvent.KEYCODE_ENTER&&event.getAction()==KeyEvent.ACTION_UP){  
                   out.println("enter");
                 return true;
              }
        return false;
            }
    });

TextWatcher Code:

  private TextWatcher watcher = new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count)    {
        if(count>0){
        out.println(":"+s.subSequence(start, start+count).toString());
        }
    }
            .
            .
            .

, TextWatcher onTextChanged, onkeylistener. , . Textwatcher , , ..

, (soft), .

+5
1

, , . Textwatcher if:

if(s.toString().substring(start).contains("\n"))

, 'enter', , , .

+1

All Articles