How to make Enter key the same as the Space Bar key - Android

user2779973

I have an EditText and when a user uses the enter key it creates a new line. I want the enter key to only make a single space, not a new line. I have no idea to do this. The reason I want to is because when the user clicks Enter it creates a new line and when they submit the message its stored and the database with an empty line and then when its retrieved and displayed on the android phone it displays and empty line.

nedaRM

Try this:

 final EditText edittext = (EditText) findViewById(R.id.edittext);
    edittext.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 ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                (keyCode == KeyEvent.KEYCODE_ENTER)) {
              // Perform action on key press
              editText.setText(editText.getText() + " ");
              return true;
            }
            return true;
        }
    });

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to make a function do something when the enter key is pressed

분류에서Dev

how to make android api key for the client mobile ip adress?

분류에서Dev

How to add a key event handler that listens for the Space key?

분류에서Dev

PHP How to sum values of the array of the same key

분류에서Dev

How to make another key instead of replacing it in firebase

분류에서Dev

How to make a list as a key of dict in Python?

분류에서Dev

How to make sure only one key is pressed

분류에서Dev

Console input and ENTER key with Java

분류에서Dev

How to update sub document whose parent key has space in?

분류에서Dev

Bash: space as a key in an associative array

분류에서Dev

How to find which key is pressed on Android softKeyboard?

분류에서Dev

Linux make return + <key> = ctrl- <key>

분류에서Dev

How to make dynamic Product URL key in phtml file for magento shop

분류에서Dev

Visual Studio: how to make pressing tab key indent the whole line

분류에서Dev

How do I make a function run again on a key press?

분류에서Dev

Handle Enter key up event with GwtQuery

분류에서Dev

jQuery dialog not working when pressing Enter Key

분류에서Dev

Call a javascript function when enter key is pressed

분류에서Dev

How to disable ENTER key when a asp.net textarea is in readonly mode

분류에서Dev

merge two tuples with same key

분류에서Dev

How to disable the Option-Space key combination for non-breaking spaces?

분류에서Dev

How to make keypress handle Enter

분류에서Dev

How to change action key of android custom keyboard according to the text field?

분류에서Dev

How to use Google public API access key in android application?

분류에서Dev

F2 function key and same key in eclipse

분류에서Dev

How to put a dot in the key?

분류에서Dev

MS Access Form - Enter key not moving to new line

분류에서Dev

Autohotkey key sequence not detected (win-alt-enter) '#' and '!' getting ignored

분류에서Dev

Update observable bound to input value only on enter key press

Related 관련 기사

  1. 1

    How to make a function do something when the enter key is pressed

  2. 2

    how to make android api key for the client mobile ip adress?

  3. 3

    How to add a key event handler that listens for the Space key?

  4. 4

    PHP How to sum values of the array of the same key

  5. 5

    How to make another key instead of replacing it in firebase

  6. 6

    How to make a list as a key of dict in Python?

  7. 7

    How to make sure only one key is pressed

  8. 8

    Console input and ENTER key with Java

  9. 9

    How to update sub document whose parent key has space in?

  10. 10

    Bash: space as a key in an associative array

  11. 11

    How to find which key is pressed on Android softKeyboard?

  12. 12

    Linux make return + <key> = ctrl- <key>

  13. 13

    How to make dynamic Product URL key in phtml file for magento shop

  14. 14

    Visual Studio: how to make pressing tab key indent the whole line

  15. 15

    How do I make a function run again on a key press?

  16. 16

    Handle Enter key up event with GwtQuery

  17. 17

    jQuery dialog not working when pressing Enter Key

  18. 18

    Call a javascript function when enter key is pressed

  19. 19

    How to disable ENTER key when a asp.net textarea is in readonly mode

  20. 20

    merge two tuples with same key

  21. 21

    How to disable the Option-Space key combination for non-breaking spaces?

  22. 22

    How to make keypress handle Enter

  23. 23

    How to change action key of android custom keyboard according to the text field?

  24. 24

    How to use Google public API access key in android application?

  25. 25

    F2 function key and same key in eclipse

  26. 26

    How to put a dot in the key?

  27. 27

    MS Access Form - Enter key not moving to new line

  28. 28

    Autohotkey key sequence not detected (win-alt-enter) '#' and '!' getting ignored

  29. 29

    Update observable bound to input value only on enter key press

뜨겁다태그

보관