Beispiel #1
0
  @Override
  public void onClick(@NonNull final View widget) {
    if (!(widget instanceof MentionsEditText)) {
      return;
    }

    // Get reference to the MentionsEditText
    MentionsEditText editText = (MentionsEditText) widget;
    Editable text = editText.getText();

    if (text == null) {
      return;
    }

    // Set cursor behind span in EditText
    int newCursorPos = text.getSpanEnd(this);
    editText.setSelection(newCursorPos);

    // If we are going to select this span, deselect all others
    boolean isSelected = isSelected();
    if (!isSelected) {
      editText.deselectAllSpans();
    }

    // Toggle whether the view is selected
    setSelected(!isSelected());

    // Update the span (forces it to redraw)
    editText.updateSpan(this);
  }