android.widget.TextView#addTextChangedListener ( )源码实例Demo

下面列出了android.widget.TextView#addTextChangedListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: AndroidProject   文件: InputTextHelper.java
/**
 * 添加 TextView
 *
 * @param views     传入单个或者多个 TextView
 */
public void addViews(List<TextView> views) {
    if (views == null) {
        return;
    }

    if (mViewSet == null) {
        mViewSet = views;
    } else {
        mViewSet.addAll(views);
    }

    for (TextView view : views) {
        view.addTextChangedListener(this);
    }

    // 触发一次监听
    notifyChanged();
}
 
源代码2 项目: AndroidProject   文件: InputTextHelper.java
/**
 * 添加 TextView
 *
 * @param views     传入单个或者多个 TextView
 */
public void addViews(TextView... views) {
    if (views == null) {
        return;
    }

    if (mViewSet == null) {
        mViewSet = new ArrayList<>(views.length);
    }

    for (TextView view : views) {
        // 避免重复添加
        if (!mViewSet.contains(view)) {
            view.addTextChangedListener(this);
            mViewSet.add(view);
        }
    }
    // 触发一次监听
    notifyChanged();
}
 
源代码3 项目: Elf-Editor   文件: MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	// 设置主界面布局文件
	setContentView(R.layout.string_list);
	// 初始化列表控件
	stringListView = (ListView) findViewById(R.id.list_res_string);
	// 初始化显示资源类型的文本框
	textCategory = (TextView) findViewById(R.id.textCategory);
	// 为显示资源类型的文本框设置点击事件的监听器
	textCategory.setOnClickListener(MyOnClickListener);
	// 为显示资源类型的文本框设置文本内容改变的监听器
	textCategory.addTextChangedListener(textWatcher);
	// 初始化数据适配器
	mAdapter = new stringListAdapter(this);
	// 为列表控件设置数据适配器
	stringListView.setAdapter(mAdapter);
	this.OpenSystemFile();
}
 
源代码4 项目: decoro   文件: FormatWatcher.java
/**
 * @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();
}
 
源代码5 项目: socialview   文件: SocialViewHelper.java
/**
 * Configuring {@link SocialView} into given view.
 *
 * @param view  TextView to install SocialView into.
 * @param attrs The attributes from the View's constructor.
 */
public SocialViewHelper(@NonNull TextView view, @Nullable AttributeSet attrs) {
    this.view = view;
    this.initialMovementMethod = view.getMovementMethod();

    view.addTextChangedListener(textWatcher);
    view.setText(view.getText(), TextView.BufferType.SPANNABLE);
    final TypedArray a = view.getContext().obtainStyledAttributes(
        attrs, R.styleable.SocialView, R.attr.socialViewStyle, R.style.Widget_SocialView
    );
    flags = a.getInteger(R.styleable.SocialView_socialFlags, FLAG_HASHTAG | FLAG_MENTION | FLAG_HYPERLINK);
    hashtagColors = a.getColorStateList(R.styleable.SocialView_hashtagColor);
    mentionColors = a.getColorStateList(R.styleable.SocialView_mentionColor);
    hyperlinkColors = a.getColorStateList(R.styleable.SocialView_hyperlinkColor);
    a.recycle();
    recolorize();
}
 
源代码6 项目: ngAndroid   文件: NgChange.java
@Override
public void attach(Scope scope, View view, int layoutId, int viewId, Tuple<String, String>[] models){
    Executor executor = new Executor(scope, layoutId, viewId, getAttribute());
    if(view instanceof CompoundButton){
        CompoundButton button = (CompoundButton) view;
        button.setOnCheckedChangeListener(executor);
    }else if(view instanceof TextView){
        TextView textView = (TextView) view;
        textView.addTextChangedListener(executor);
    }else if(view instanceof Spinner){
        Spinner spinner = (Spinner) view;
        spinner.setOnItemSelectedListener(executor);
    }else if(view instanceof RadioGroup){
        RadioGroup group = (RadioGroup) view;
        group.setOnCheckedChangeListener(executor);
    }
}
 
源代码7 项目: travelguide   文件: ArticleInfoListFragment.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
  mRootView = inflater.inflate(R.layout.fragment_articleinfo_list, null, false);
  mSearchText = (TextView) mRootView.findViewById(R.id.searchText);
  mCross = mRootView.findViewById(R.id.clearSearch);

  mListContainer = mRootView.findViewById(R.id.listContainer);
  mProgressContainer = mRootView.findViewById(R.id.progressContainer);
  mHeader = mRootView.findViewById(R.id.header);
  mAbout = mRootView.findViewById(R.id.about);
  mShowMapForAll = mRootView.findViewById(R.id.showMapForAll);

  // setup listeners
  mSearchText.addTextChangedListener(this);
  mCross.setOnClickListener(this);
  mAbout.setOnClickListener(this);
  mShowMapForAll.setOnClickListener(this);

  return mRootView;
}
 
源代码8 项目: ans-android-sdk   文件: BaseViewVisitor.java
@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);
    }
}
 
源代码9 项目: green_android   文件: DisplayMnemonicActivity.java
private void setUpTable(final int id, final int startWordNum) {
    int wordNum = startWordNum;
    final TableLayout table = UI.find(this, id);

    for (int y = 0; y < table.getChildCount(); ++y) {
        final TableRow row = (TableRow) table.getChildAt(y);

        for (int x = 0; x < row.getChildCount() / 2; ++x) {
            ((TextView) row.getChildAt(x * 2)).setText(String.valueOf(wordNum));

            TextView me = (TextView) row.getChildAt(x * 2 + 1);
            me.setInputType(0);
            me.addTextChangedListener(new UI.TextWatcher() {
                @Override
                public void afterTextChanged(final Editable s) {
                    super.afterTextChanged(s);
                    final String original = s.toString();
                    final String trimmed = original.trim();
                    if (!trimmed.isEmpty() && !trimmed.equals(original)) {
                        me.setText(trimmed);
                    }
                }
            });
            registerForContextMenu(me);

            mTextViews[wordNum - 1] = me;
            ++wordNum;
        }
    }
}
 
源代码10 项目: CountryCodePicker   文件: CountryCodePicker.java
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);
    }
  }
}
 
源代码11 项目: BetterWeather   文件: WeatherLocationPreference.java
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Context layoutContext = new ContextThemeWrapper(getActivity(),
            android.R.style.Theme_DeviceDefault_Light_Dialog);

    LayoutInflater layoutInflater = LayoutInflater.from(layoutContext);
    View rootView = layoutInflater.inflate(R.layout.dialog_weather_location_chooser, null);
    TextView searchView = (TextView) rootView.findViewById(R.id.location_query);
    searchView.addTextChangedListener(this);

    // Set up apps
    mSearchResultsList = (ListView) rootView.findViewById(android.R.id.list);
    mSearchResultsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> listView, View view,
                                int position, long itemId) {
            String value = mSearchResultsAdapter.getPrefValueAt(position);
            if (value == null || "".equals(value)) {
                if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
                        ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                    ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_REQUEST_CODE);
                }
            }
            mPreference.setValue(value);
            dismiss();
        }
    });

    tryBindList();

    AlertDialog dialog = new AlertDialog.Builder(getActivity())
            .setView(rootView)
            .create();
    dialog.getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    return dialog;
}
 
源代码12 项目: ScalableLayout   文件: ScalableLayout.java
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);
    }
}
 
源代码13 项目: Emojix   文件: Emojix.java
public static void wrapView(View view) {
    if (view == null) return;

    if (view instanceof TextView) {
        TextView textView = (TextView) view;
        if (textView.getTag(R.id.tag_emojix_watcher) == null) {
            EmojixTextWatcher watcher = new EmojixTextWatcher(textView);
            textView.addTextChangedListener(watcher);

            textView.setTag(R.id.tag_emojix_watcher, watcher);
        }

    } else if (view instanceof ViewGroup) {
        if (view.getTag(R.id.tag_layout_listener) == null) {
            View.OnLayoutChangeListener listener = new View.OnLayoutChangeListener() {
                @Override
                public void onLayoutChange(View v, int left, int top, int right, int bottom,
                                           int oldLeft, int oldTop, int oldRight, int oldBottom) {

                    ViewGroup parentView = (ViewGroup) v;
                    int len = parentView.getChildCount();
                    for (int i = 0; i < len; i ++) {
                        wrapView(parentView.getChildAt(i));
                    }
                }
            };
            view.addOnLayoutChangeListener(listener);

            view.setTag(R.id.tag_layout_listener, listener);
        }
    }
}
 
源代码14 项目: YTPlayer   文件: RingdroidEditActivity.java
/**
 * Called from both onCreate and onConfigurationChanged
 * (if the user switched layouts)
 */
private void loadGui() {
    // Inflate our UI from its XML layout description.
    setContentView(R.layout.editor);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    mToolbar.setNavigationOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });

    mStartText = (TextView) findViewById(R.id.starttext);
    mStartText.addTextChangedListener(mTextWatcher);

    mEndText = (TextView) findViewById(R.id.endtext);
    mEndText.addTextChangedListener(mTextWatcher);


    mPlayButton = (ImageButton) findViewById(R.id.play);
    mPlayButton.setOnClickListener(mPlayListener);
    mRewindButton = (ImageButton) findViewById(R.id.rew);
    mRewindButton.setOnClickListener(mRewindListener);
    mFfwdButton = (ImageButton) findViewById(R.id.ffwd);
    mFfwdButton.setOnClickListener(mFfwdListener);

    TextView markStartButton = (TextView) findViewById(R.id.mark_start);
    markStartButton.setOnClickListener(mMarkStartListener);

    TextView markEndButton = (TextView) findViewById(R.id.mark_end);
    markEndButton.setOnClickListener(mMarkEndListener);

    enableDisableButtons();

    mWaveformView = (WaveformView) findViewById(R.id.waveform);
    mWaveformView.setListener(this);

    mInfo = (TextView) findViewById(R.id.info);
    mInfo.setText(mCaption);

    mMaxPos = 0;
    mLastDisplayedStartPos = -1;
    mLastDisplayedEndPos = -1;

    if (mSoundFile != null && !mWaveformView.hasSoundFile()) {
        mWaveformView.setSoundFile(mSoundFile);
        mWaveformView.recomputeHeights(mDensity);
        mMaxPos = mWaveformView.maxPos();
    }

    mStartMarker = (MarkerView) findViewById(R.id.startmarker);
    mStartMarker.setListener(this);
    mStartMarker.setAlpha(1f);
    mStartMarker.setFocusable(true);
    mStartMarker.setFocusableInTouchMode(true);
    mStartVisible = true;

    mEndMarker = (MarkerView) findViewById(R.id.endmarker);
    mEndMarker.setListener(this);
    mEndMarker.setAlpha(1f);
    mEndMarker.setFocusable(true);
    mEndMarker.setFocusableInTouchMode(true);
    mEndVisible = true;

    updateDisplay();
}
 
源代码15 项目: ArscEditor   文件: MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	// 设置主界面布局文件
	setContentView(R.layout.string_list);
	// 初始化列表控件
	stringListView = (ListView) findViewById(R.id.list_res_string);
	// 初始化显示资源类型的文本框
	textCategory = (TextView) findViewById(R.id.textCategory);
	// 初始化显示资源Config的文本框
	textConfig = (TextView) findViewById(R.id.textConfig);
	// 初始化翻译按钮
	btnTranslate = (ImageView) findViewById(R.id.btnTranslate);
	// 初始化搜索按钮
	btnSearch = (ImageView) findViewById(R.id.btnSearch);
	// 初始化保存按钮
	btnSave = (ImageView) findViewById(R.id.btnSave);
	// 获取用来显示信息的文本框
	info = (TextView) findViewById(R.id.info);
	// 为显示资源类型的文本框设置点击事件的监听器
	textCategory.setOnClickListener(MyOnClickListener);
	// 为显示资源Config的文本框设置点击事件的监听器
	textConfig.setOnClickListener(MyOnClickListener);
	// 为显示资源类型的文本框设置文本内容改变的监听器
	textCategory.addTextChangedListener(textWatcher);
	// 为显示资源Config的文本框设置文本内容改变的监听器
	textConfig.addTextChangedListener(textWatcher);
	// 为翻译按钮设置点击事件监听器
	btnTranslate.setOnClickListener(MyOnClickListener);
	// 为搜索按钮设置点击事件监听器
	btnSearch.setOnClickListener(MyOnClickListener);
	// 为保存按钮设置点击事件监听器
	btnSave.setOnClickListener(MyOnClickListener);
	// 初始化数据适配器
	mAdapter = new stringListAdapter(this);
	// 为列表控件设置数据适配器
	stringListView.setAdapter(mAdapter);
	// 为列表控件设置长按事件监听器
	stringListView.setOnItemLongClickListener(this);
	try {
		open("/sdcard/resources.arsc");
	} catch (IOException e) {
		showMessage(this, e.toString()).show();
	}
}
 
源代码16 项目: PowerfulRecyclerViewAdapter   文件: HolderHelper.java
@Override
public void setTextWatcher( @IdRes int id, TextWatcherAdapter watcherAdapter ) {
  TextView targetTxt = getView(id);
  if (targetTxt != null)
    targetTxt.addTextChangedListener(watcherAdapter);
}
 
源代码17 项目: ShaderEditor   文件: UndoRedo.java
public UndoRedo(TextView textView, EditHistory editHistory) {
	this.textView = textView;
	this.editHistory = editHistory;
	textView.addTextChangedListener(changeListener);
}
 
源代码18 项目: Conversations   文件: TextDrawable.java
/**
 * Create a TextDrawable. This uses the given TextView to initialize paint and has initial text
 * that will be drawn. Initial text can also be useful for reserving space that may otherwise
 * not be available when setting compound drawables.
 *
 * @param tv               The TextView / EditText using to initialize this drawable
 * @param initialText      Optional initial text to display
 * @param bindToViewsText  Should this drawable mirror the text in the TextView
 * @param bindToViewsPaint Should this drawable mirror changes to Paint in the TextView, like textColor, typeface, alpha etc.
 *                         Note, this will override any changes made using setColorFilter or setAlpha.
 */
public TextDrawable(TextView tv, String initialText, boolean bindToViewsText, boolean bindToViewsPaint) {
    this(tv.getPaint(), initialText);
    ref = new WeakReference<>(tv);
    if (bindToViewsText || bindToViewsPaint) {
        if (bindToViewsText) {
            tv.addTextChangedListener(this);
        }
        mBindToViewPaint = bindToViewsPaint;
    }
}
 
源代码19 项目: stynico   文件: TextDrawable.java
/**
 * Create a TextDrawable. This uses the given TextView to initialize paint and has initial text
 * that will be drawn. Initial text can also be useful for reserving space that may otherwise
 * not be available when setting compound drawables.
 *
 * @param tv               The TextView / EditText using to initialize this drawable
 * @param initialText      Optional initial text to display
 * @param bindToViewsText  Should this drawable mirror the text in the TextView
 * @param bindToViewsPaint Should this drawable mirror changes to Paint in the TextView, like textColor, typeface, alpha etc.
 *                         Note, this will override any changes made using setColorFilter or setAlpha.
 */
public TextDrawable(TextView tv, String initialText, boolean bindToViewsText, boolean bindToViewsPaint) {
    this(tv.getPaint(), initialText);
    ref = new WeakReference<>(tv);
    if (bindToViewsText || bindToViewsPaint) {
        if (bindToViewsText) {
            tv.addTextChangedListener(this);
        }
        mBindToViewPaint = bindToViewsPaint;
    }
}
 
源代码20 项目: AnimatedEditText   文件: TextDrawable.java
/**
 * Create a TextDrawable. This uses the given TextView to initialize paint and has initial text
 * that will be drawn. Initial text can also be useful for reserving space that may otherwise
 * not be available when setting compound drawables.
 *
 * @param tv               The TextView / EditText using to initialize this drawable
 * @param initialText      Optional initial text to display
 * @param bindToViewsText  Should this drawable mirror the text in the TextView
 * @param bindToViewsPaint Should this drawable mirror changes to Paint in the TextView, like textColor, typeface, alpha etc.
 *                         Note, this will override any changes made using setColorFilter or setAlpha.
 */
public TextDrawable(TextView tv, String initialText, boolean bindToViewsText, boolean bindToViewsPaint) {
    this(tv.getPaint(), initialText);
    ref = new WeakReference<>(tv);
    if (bindToViewsText || bindToViewsPaint) {
        if (bindToViewsText) {
            tv.addTextChangedListener(this);
        }
        mBindToViewPaint = bindToViewsPaint;
    }
}
 
 方法所在类
 同类方法