code: public static void setSelection(Spannable text, int start, int stop) {
          // int len = text.length();
          // start = pin(start, 0, len);  XXX remove unless we really need it
          // stop = pin(stop, 0, len);
  
          int ostart = getSelectionStart(text);
          int oend = getSelectionEnd(text);
  
          if (ostart != start || oend != stop) {
              text.setSpan(SELECTION_START, start, start,
                           Spanned.SPAN_POINT_POINT|Spanned.SPAN_INTERMEDIATE);
              text.setSpan(SELECTION_END, stop, stop,
                           Spanned.SPAN_POINT_POINT);
          }
      }
docs: Set the selection anchor to <code>start</code> and the selection edge
  to <code>stop</code>.