title: Caused by: java.lang.IndexOutOfBoundsException on AutocompleteTextView
body: <p>I get this error when i try to get the position of first and last character typed by a user in an AutoCompleteTextView.</p>
  
  <p>I would appreciate any help provided.</p>
  
  <p>When i add a textChangeListener i still get the error
  java.lang.IndexOutOfBoundsException: setSpan (0 ... -1) has end before start</p>
  
  <p>This is my codes below:</p>
  
  <pre><code>final AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autocompleteView);
  
  autoCompleteTextView.setAdapter(autoComplete);
  
  autoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
      @Override
      public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) {
          //my statements
  
  
      }
  });
  
          autoCompleteTextView.addTextChangedListener(new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  
          }
  
          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
              //int start = startText.indexOf(0);
              String startText = autoCompleteTextView.getText().toString();
              int end = startText.indexOf(1);
              SpannableStringBuilder builder = new SpannableStringBuilder(startText);
              // set foreground color (text color) - optional, you may not want to change the text color too
              builder.setSpan(new ForegroundColorSpan(Color.RED), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
              // set background color
              builder.setSpan(new BackgroundColorSpan(Color.YELLOW), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
              // set result to AutoCompleteTextView
              autoCompleteTextView.setText(builder);
          }
  
          @Override
          public void afterTextChanged(Editable s) {
  
          }
      });
  </code></pre>
  
  <p>Error Log</p>
  
  <pre><code>    01-31 16:02:37.418 20357-20357/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                 Process: com.lawerh.jonathan.partygoer, PID: 20357
                                                 java.lang.IndexOutOfBoundsException: setSpan (0 ... -1) has end before start
                                                     at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1101)
                                                     at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:680)
                                                     at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:673)
                                                     at com.lawerh.jonathan.partygoer.ui.MapActivity$8.onTextChanged(MapActivity.java:328)
                                                     at android.widget.TextView.sendOnTextChanged(TextView.java:8320)
                                                     at android.widget.TextView.handleTextChanged(TextView.java:8385)
                                                     at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:10531)
                                                     at android.text.SpannableStringBuilder.sendTextChanged(SpannableStringBuilder.java:1051)
                                                     at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:572)
                                                     at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:503)
                                                     at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:502)
                                                     at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:693)
                                                     at android.view.inputmethod.BaseInputConnection.setComposingText(BaseInputConnection.java:453)
                                                     at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:340)
                                                     at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:78)
                                                     at android.os.Handler.dispatchMessage(Handler.java:111)
                                                     at android.os.Looper.loop(Looper.java:207)
                                                     at android.app.ActivityThread.main(ActivityThread.java:5728)
                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
  </code></pre>