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

The following examples show how to use android.widget.TextView#addTextChangedListener() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: AndroidProject   File: InputTextHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 添加 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();
}
 
Example 2
Source Project: AndroidProject   File: InputTextHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 添加 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();
}
 
Example 3
@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();
}
 
Example 4
Source Project: decoro   File: FormatWatcher.java    License: 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 5
Source Project: socialview   File: SocialViewHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example 6
Source Project: ngAndroid   File: NgChange.java    License: Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example 7
@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;
}
 
Example 8
@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 9
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;
        }
    }
}
 
Example 10
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 11
@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;
}
 
Example 12
Source Project: ScalableLayout   File: ScalableLayout.java    License: 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 13
Source Project: Emojix   File: Emojix.java    License: Apache License 2.0 5 votes vote down vote up
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);
        }
    }
}
 
Example 14
/**
 * 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();
}
 
Example 15
Source Project: ArscEditor   File: MainActivity.java    License: Apache License 2.0 4 votes vote down vote up
@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();
	}
}
 
Example 16
@Override
public void setTextWatcher( @IdRes int id, TextWatcherAdapter watcherAdapter ) {
  TextView targetTxt = getView(id);
  if (targetTxt != null)
    targetTxt.addTextChangedListener(watcherAdapter);
}
 
Example 17
Source Project: ShaderEditor   File: UndoRedo.java    License: MIT License 4 votes vote down vote up
public UndoRedo(TextView textView, EditHistory editHistory) {
	this.textView = textView;
	this.editHistory = editHistory;
	textView.addTextChangedListener(changeListener);
}
 
Example 18
/**
 * 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;
    }
}
 
Example 19
Source Project: stynico   File: TextDrawable.java    License: MIT License 3 votes vote down vote up
/**
 * 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;
    }
}
 
Example 20
Source Project: AnimatedEditText   File: TextDrawable.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * 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;
    }
}