getText from Edit Text when new line added
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
.
精彩评论