public static void appendText(InputConnection connection,String newText){
  if (connection == null) {
    return;
  }
  connection.finishComposingText();
  CharSequence charBeforeCursor=connection.getTextBeforeCursor(1,0);
  if (charBeforeCursor != null && !charBeforeCursor.equals(" ") && (charBeforeCursor.length() > 0)) {
    newText=" " + newText;
  }
  connection.setComposingText(newText,1);
}

public static void appendText ( InputConnection connection , String newText ) { if ( connection == null ) { return ; } connection . finishComposingText ( ) ; CharSequence charBeforeCursor = connection . getTextBeforeCursor ( 1 , 0 ) ; if ( charBeforeCursor != null && ! charBeforeCursor . equals ( " " ) && ( charBeforeCursor . length ( ) > 0 ) ) { newText = " " + newText ; } connection . setComposingText ( newText , 1 ) ; }
append newtext to the text field represented by connection . the new text becomes selected .
