1 /* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.text; 18 19 /** 20 * When an object of this type is attached to an Editable, its methods will 21 * be called when the text is changed. 22 */ 23 @android.ravenwood.annotation.RavenwoodKeepWholeClass 24 public interface TextWatcher extends NoCopySpan { 25 /** 26 * This method is called to notify you that, within <code>s</code>, 27 * the <code>count</code> characters beginning at <code>start</code> 28 * are about to be replaced by new text with length <code>after</code>. 29 * It is an error to attempt to make changes to <code>s</code> from 30 * this callback. 31 */ beforeTextChanged(CharSequence s, int start, int count, int after)32 public void beforeTextChanged(CharSequence s, int start, 33 int count, int after); 34 /** 35 * This method is called to notify you that, within <code>s</code>, 36 * the <code>count</code> characters beginning at <code>start</code> 37 * have just replaced old text that had length <code>before</code>. 38 * It is an error to attempt to make changes to <code>s</code> from 39 * this callback. 40 */ onTextChanged(CharSequence s, int start, int before, int count)41 public void onTextChanged(CharSequence s, int start, int before, int count); 42 43 /** 44 * This method is called to notify you that, somewhere within 45 * <code>s</code>, the text has been changed. 46 * It is legitimate to make further changes to <code>s</code> from 47 * this callback, but be careful not to get yourself into an infinite 48 * loop, because any changes you make will cause this method to be 49 * called again recursively. 50 * (You are not told where the change took place because other 51 * afterTextChanged() methods may already have made other changes 52 * and invalidated the offsets. But if you need to know here, 53 * you can use {@link Spannable#setSpan} in {@link #onTextChanged} 54 * to mark your place and then look up from here where the span 55 * ended up. 56 */ afterTextChanged(Editable s)57 public void afterTextChanged(Editable s); 58 } 59