diff --git a/cocos/2d/platform/android/java/src/org/cocos2dx/lib/Cocos2dxTextInputWraper.java b/cocos/2d/platform/android/java/src/org/cocos2dx/lib/Cocos2dxTextInputWraper.java index bbf2a038a7..682661600b 100644 --- a/cocos/2d/platform/android/java/src/org/cocos2dx/lib/Cocos2dxTextInputWraper.java +++ b/cocos/2d/platform/android/java/src/org/cocos2dx/lib/Cocos2dxTextInputWraper.java @@ -123,25 +123,30 @@ public class Cocos2dxTextInputWraper implements TextWatcher, OnEditorActionListe public boolean onEditorAction(final TextView pTextView, final int pActionID, final KeyEvent pKeyEvent) { if (this.mCocos2dxGLSurfaceView.getCocos2dxEditText() == pTextView && this.isFullScreenEdit()) { // user press the action button, delete all old text and insert new text - for (int i = this.mOriginText.length(); i > 0; i--) { - this.mCocos2dxGLSurfaceView.deleteBackward(); - /* - if (BuildConfig.DEBUG) { - Log.d(TAG, "deleteBackward"); + if (null != mOriginText) { + for (int i = this.mOriginText.length(); i > 0; i--) { + this.mCocos2dxGLSurfaceView.deleteBackward(); + /* + if (BuildConfig.DEBUG) { + Log.d(TAG, "deleteBackward"); + } + */ } - */ } + String text = pTextView.getText().toString(); + + if (text != null) { + /* If user input nothing, translate "\n" to engine. */ + if ( text.compareTo("") == 0) { + text = "\n"; + } - /* If user input nothing, translate "\n" to engine. */ - if (text.compareTo("") == 0) { - text = "\n"; + if ( '\n' != text.charAt(text.length() - 1)) { + text += '\n'; + } } - - if ('\n' != text.charAt(text.length() - 1)) { - text += '\n'; - } - + final String insertText = text; this.mCocos2dxGLSurfaceView.insertText(insertText); /*