Java Code Examples for android.widget.TextView#removeTextChangedListener()

The following examples show how to use android.widget.TextView#removeTextChangedListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FormatWatcher.java    From decoro with Apache License 2.0 6 votes vote down vote up
/**
 * @param textView     an observable text view which content text will be formatted using
 *                     {@link
 *                     Mask}
 * @param initWithMask this flags defines whether hardcoded head of the mask (e.g "+7 ") will
 *                     fill the initial text of the {@code textView}.
 */
protected void installOn(final TextView textView, final boolean initWithMask) {
    if (textView == null) {
        throw new IllegalArgumentException("text view cannot be null");
    }

    this.textView = textView;
    this.initWithMask = initWithMask;

    // try to remove us from listeners (useful in case user's trying to install the formatter twice on a same TextView)
    textView.removeTextChangedListener(this);

    textView.addTextChangedListener(this);

    this.mask = null;
    refreshMask();
}
 
Example 2
Source File: BaseViewVisitor.java    From ans-android-sdk with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void cleanup() {
    for (final Map.Entry<TextView, TextWatcher> entry : mWatching.entrySet()) {
        final TextView v = entry.getKey();
        final TextWatcher watcher = entry.getValue();
        v.removeTextChangedListener(watcher);
    }

    mWatching.clear();
}
 
Example 3
Source File: BaseViewVisitor.java    From ans-android-sdk with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void accumulate(View found) {
    if (found instanceof TextView) {
        final TextView foundTextView = (TextView) found;
        final TextWatcher watcher = new TrackingTextWatcher(foundTextView);
        final TextWatcher oldWatcher = mWatching.get(foundTextView);
        if (null != oldWatcher) {
            foundTextView.removeTextChangedListener(oldWatcher);
        }
        foundTextView.addTextChangedListener(watcher);
        mWatching.put(foundTextView, watcher);
    }
}
 
Example 4
Source File: InputTextHelper.java    From AndroidProject with Apache License 2.0 5 votes vote down vote up
/**
 * 移除 TextView 监听,避免内存泄露
 */
public void removeViews(TextView... views) {
    if (mViewSet != null && mViewSet.size() > 0) {
        for (TextView view : views) {
            view.removeTextChangedListener(this);
            mViewSet.remove(view);
        }
        // 触发一次监听
        notifyChanged();
    }
}
 
Example 5
Source File: InputTextHelper.java    From AndroidProject with Apache License 2.0 5 votes vote down vote up
/**
 * 移除所有 TextView 监听,避免内存泄露
 */
public void removeAllViews() {
    if (mViewSet == null) {
        return;
    }

    for (TextView view : mViewSet) {
        view.removeTextChangedListener(this);
    }
    mViewSet.clear();
    mViewSet = null;
}
 
Example 6
Source File: CountryCodePicker.java    From CountryCodePicker with Apache License 2.0 5 votes vote down vote up
private void setPhoneNumberWatcherToTextView(TextView textView, String countryNameCode) {
  if (!mIsEnablePhoneNumberWatcher) return;

  if (mPhoneNumberWatcher == null) {
    mPhoneNumberWatcher = new PhoneNumberWatcher(countryNameCode);
    textView.addTextChangedListener(mPhoneNumberWatcher);
  } else {
    if (!mPhoneNumberWatcher.getPreviousCountryCode().equalsIgnoreCase(countryNameCode)) {
      textView.removeTextChangedListener(mPhoneNumberWatcher);
      mPhoneNumberWatcher = new PhoneNumberWatcher(countryNameCode);
      textView.addTextChangedListener(mPhoneNumberWatcher);
    }
  }
}
 
Example 7
Source File: ScalableLayout.java    From ScalableLayout with Apache License 2.0 5 votes vote down vote up
private void refreshTextChangedListener(TextView pTextView) {
    LayoutParams lSLLP = getChildLayoutParams(pTextView);

    try {
        pTextView.removeTextChangedListener(mTextWatcher);
    } catch (Throwable e) {
        ex(e);
    }
    if(lSLLP.mTextView_WrapContent_Direction != TextView_WrapContent_Direction.None) {
        pTextView.addTextChangedListener(mTextWatcher);
    }
}
 
Example 8
Source File: WhatsappViewCompat.java    From WhatsappFormatter with Apache License 2.0 2 votes vote down vote up
/**
 * Default modifier for removing text change listener
 * @param textView - related text view.
 * @param watcher - text watcher which has to be removed.
 */
static void removeTextChangedListener(TextView textView, TextWatcher watcher) {
    textView.removeTextChangedListener(watcher);
}