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.
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] 삭제
몇 마디 만하겠습니다