Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Soft keyboard enter key event handle

Tags:

android

I want to do some stuff on soft keyboard enter key press. See my code and output below. It executes twice, but I want it to be executed only once. How to fix it?

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    txt = (EditText)findViewById(R.id.txt);
    txt.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                Log.e("test","--------- on enter");
                return false;
            }
            return false;
        }
    });
}

This is my output for this

like image 448
Yog Guru Avatar asked Sep 30 '11 13:09

Yog Guru


People also ask

How do I change the enter key?

Go to More options > Settings > Chats . Turn Enter is send on or off.

What is the symbol for enter?

All Microsoft keyboards uses ↵ a thin turned arrow with a sharp 90° corner. This is the most popular graphic symbol used. If a keyboard use a return arrow symbol, it's usually with sharp 90° corner like this.

How do I get the enter key on my Samsung keyboard?

The first is in Settings (tap the three dots when viewing your conversations) > Scroll down to Sending and uncheck Send using Enter. If you're having the smiley issue, keep scrolling down to the bottom and tap Keyboard. In that menu it says Smiley or Enter - make sure yours is set to enter. Hope that helps.


1 Answers

The best way possible:

if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {
    Log.d(TAG, "enter_key_called");
}
like image 100
Lalit Poptani Avatar answered Oct 16 '22 16:10

Lalit Poptani