本文整理了Java中android.widget.TextView.addTextChangedListener()
方法的一些代码示例,展示了TextView.addTextChangedListener()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.addTextChangedListener()
方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:addTextChangedListener
暂无
代码示例来源:origin: facebook/stetho
public void hook(TextView element) {
mElement = Util.throwIfNull(element);
mElement.addTextChangedListener(this);
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected void addTextChangedListener(TextWatcher watcher) {
this.watchers.add(watcher);
directlyOn(realTextView, TextView.class).addTextChangedListener(watcher);
}
代码示例来源:origin: TommyLemon/APIJSON
tv.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
代码示例来源:origin: TommyLemon/Android-ZBLibrary
tv.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
代码示例来源:origin: chrisjenx/Calligraphy
if (deferred) {
textView.setText(applyTypefaceSpan(textView.getText(), typeface), TextView.BufferType.SPANNABLE);
textView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
代码示例来源:origin: robolectric/robolectric
@Test
public void whenSettingText_ShouldFireBeforeTextChangedWithCorrectArguments() {
textView.setText(INITIAL_TEXT);
TextWatcher mockTextWatcher = mock(TextWatcher.class);
textView.addTextChangedListener(mockTextWatcher);
textView.setText(NEW_TEXT);
verify(mockTextWatcher).beforeTextChanged(INITIAL_TEXT, 0, INITIAL_TEXT.length(), NEW_TEXT.length());
}
代码示例来源:origin: robolectric/robolectric
@Test
public void whenAppendingText_ShouldFireBeforeTextChangedWithCorrectArguments() {
textView.setText(INITIAL_TEXT);
TextWatcher mockTextWatcher = mock(TextWatcher.class);
textView.addTextChangedListener(mockTextWatcher);
textView.append(NEW_TEXT);
verify(mockTextWatcher).beforeTextChanged(eq(INITIAL_TEXT), eq(0), eq(INITIAL_TEXT.length()), eq(INITIAL_TEXT.length()));
}
代码示例来源:origin: robolectric/robolectric
@Test
public void whenSettingText_ShouldFireOnTextChangedWithCorrectArguments() {
textView.setText(INITIAL_TEXT);
TextWatcher mockTextWatcher = mock(TextWatcher.class);
textView.addTextChangedListener(mockTextWatcher);
textView.setText(NEW_TEXT);
ArgumentCaptor<SpannableStringBuilder> builderCaptor = ArgumentCaptor.forClass(SpannableStringBuilder.class);
verify(mockTextWatcher).onTextChanged(builderCaptor.capture(), eq(0), eq(INITIAL_TEXT.length()), eq(NEW_TEXT.length()));
assertThat(builderCaptor.getValue().toString()).isEqualTo(NEW_TEXT);
}
代码示例来源:origin: androidquery/androidquery
/**
* Register a callback method for when a textview text is changed. Method must have signature of method(CharSequence s, int start, int before, int count)).
*
* @param handler The handler that has the public callback method.
* @param method The method name of the callback.
* @return self
*/
public T textChanged(Object handler, String method){
if(view instanceof TextView){
TextView tv = (TextView) view;
Common common = new Common().forward(handler, method, true, TEXT_CHANGE_SIG);
tv.addTextChangedListener(common);
}
return self();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void whenSettingTextToNull_WatchersSeeEmptyString() {
TextWatcher mockTextWatcher = mock(TextWatcher.class);
textView.addTextChangedListener(mockTextWatcher);
textView.setText(null);
ArgumentCaptor<SpannableStringBuilder> builderCaptor = ArgumentCaptor.forClass(SpannableStringBuilder.class);
verify(mockTextWatcher).onTextChanged(builderCaptor.capture(), eq(0), eq(0), eq(0));
assertThat(builderCaptor.getValue().toString()).isEmpty();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void whenAppendingText_ShouldFireOnTextChangedWithCorrectArguments() {
textView.setText(INITIAL_TEXT);
TextWatcher mockTextWatcher = mock(TextWatcher.class);
textView.addTextChangedListener(mockTextWatcher);
textView.append(NEW_TEXT);
ArgumentCaptor<SpannableStringBuilder> builderCaptor = ArgumentCaptor.forClass(SpannableStringBuilder.class);
verify(mockTextWatcher).onTextChanged(builderCaptor.capture(), eq(0), eq(INITIAL_TEXT.length()), eq(INITIAL_TEXT.length()));
assertThat(builderCaptor.getValue().toString()).isEqualTo(INITIAL_TEXT + NEW_TEXT);
}
代码示例来源:origin: grantland/android-autofittextview
/**
* Set the enabled state of automatically resizing text.
*/
public AutofitHelper setEnabled(boolean enabled) {
if (mEnabled != enabled) {
mEnabled = enabled;
if (enabled) {
mTextView.addTextChangedListener(mTextWatcher);
mTextView.addOnLayoutChangeListener(mOnLayoutChangeListener);
autofit();
} else {
mTextView.removeTextChangedListener(mTextWatcher);
mTextView.removeOnLayoutChangeListener(mOnLayoutChangeListener);
mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
}
}
return this;
}
代码示例来源:origin: robolectric/robolectric
@Test
public void whenSettingText_ShouldFireAfterTextChangedWithCorrectArgument() {
MockTextWatcher mockTextWatcher = new MockTextWatcher();
textView.addTextChangedListener(mockTextWatcher);
textView.setText(NEW_TEXT);
assertThat(mockTextWatcher.afterTextChangeArgument.toString()).isEqualTo(NEW_TEXT);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void whenAppendingText_ShouldFireAfterTextChangedWithCorrectArgument() {
textView.setText(INITIAL_TEXT);
MockTextWatcher mockTextWatcher = new MockTextWatcher();
textView.addTextChangedListener(mockTextWatcher);
textView.append(NEW_TEXT);
assertThat(mockTextWatcher.afterTextChangeArgument.toString()).isEqualTo(INITIAL_TEXT + NEW_TEXT);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void givenATextViewWithATextWatcherAdded_WhenSettingTextWithCharSequence_ShouldNotifyTextWatcher() {
MockTextWatcher mockTextWatcher = new MockTextWatcher();
textView.addTextChangedListener(mockTextWatcher);
textView.setText("text");
assertEachTextWatcherEventWasInvoked(mockTextWatcher);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void givenATextViewWithATextWatcherAdded_WhenSettingTextWithTextResourceId_ShouldNotifyTextWatcher() {
MockTextWatcher mockTextWatcher = new MockTextWatcher();
textView.addTextChangedListener(mockTextWatcher);
textView.setText(R.string.hello);
assertEachTextWatcherEventWasInvoked(mockTextWatcher);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void givenATextViewWithATextWatcherAdded_WhenSettingNullText_ShouldNotifyTextWatcher() {
MockTextWatcher mockTextWatcher = new MockTextWatcher();
textView.addTextChangedListener(mockTextWatcher);
textView.setText(null);
assertEachTextWatcherEventWasInvoked(mockTextWatcher);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void givenATextViewWithMultipleTextWatchersAdded_WhenSettingText_ShouldNotifyEachTextWatcher() {
List<MockTextWatcher> mockTextWatchers = anyNumberOfTextWatchers();
for (MockTextWatcher textWatcher : mockTextWatchers) {
textView.addTextChangedListener(textWatcher);
}
textView.setText("text");
for (MockTextWatcher textWatcher : mockTextWatchers) {
assertEachTextWatcherEventWasInvoked(textWatcher);
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void removeTextChangedListener_shouldRemoveTheListener() throws Exception {
MockTextWatcher watcher = new MockTextWatcher();
textView.addTextChangedListener(watcher);
assertTrue(shadowOf(textView).getWatchers().contains(watcher));
textView.removeTextChangedListener(watcher);
assertFalse(shadowOf(textView).getWatchers().contains(watcher));
}
代码示例来源:origin: mikepenz/Android-Iconics
((TextView) view).addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
内容来源于网络,如有侵权,请联系作者删除!