开发者

getText from Edit Text when new line added

开发者 https://www.devze.com 2023-03-05 02:52 出处:网络
Hey guys i am using 开发者_运维知识库edit text in my application. Problem arises if user touches enter button on soft keyboard then the cursor drops down to

Hey guys i am using 开发者_运维知识库edit text in my application. Problem arises if user touches enter button on soft keyboard then the cursor drops down to new line and the user starts writting on new line.

For ex the user types :-

hey

guys

instead of hey guys

Then if i try getting the text from edit Text i am shown first hey and then next log debugger shows guys so the issue is that i am able to post some part of the message only to the server not the complete message.

Thanks in advance


Try something like this:

yourEditBox.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                // intercept the return key
                return true;
            }
            return false;
        }

    });

also it might help to set the android:lines attribute of your EditText to 1.

0

精彩评论

暂无评论...
验证码 换一张
取 消