Code example for TextView

Methods: appendgetSelectionEndgetSelectionStartsetText, getEditableText

0
    assertThat(textView.getPaint().measureText("12345")).isEqualTo(5f);
  } 
 
  @Test 
  public void append_whenSelectionIsAtTheEnd_shouldKeepSelectionAtTheEnd() throws Exception { 
    textView.setText("1", TextView.BufferType.EDITABLE);
    Selection.setSelection(textView.getEditableText(), 0, 0);
    textView.append("2");
    assertEquals(0, textView.getSelectionEnd());
    assertEquals(0, textView.getSelectionStart());
 
    Selection.setSelection(textView.getEditableText(), 2, 2);
    textView.append("3");
    assertEquals(3, textView.getSelectionEnd());
    assertEquals(3, textView.getSelectionStart());
  } 
 
  @Test 
  public void append_whenSelectionReachesToEnd_shouldExtendSelectionToTheEnd() throws Exception { 
    textView.setText("12", TextView.BufferType.EDITABLE);
    Selection.setSelection(textView.getEditableText(), 0, 2);