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

The following are Jave code examples for showing how to use addTextChangedListener() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Elf-Editor   File: MainActivity.java   View Source Code Vote up 6 votes
@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 2
Project: data-mediator   File: DoubleBindUtil.java   View Source Code Vote up 5 votes
public static <T> void bindDouble(final DataMediator<T> mediator, TextView tv,
                                  final String propertyName){

    DataMediatorCallbackImpl<T> callback = new DataMediatorCallbackImpl<>(tv, propertyName);
    TextWatcherAdapterImpl<T> watcher = new TextWatcherAdapterImpl<>(tv, mediator, propertyName);
    callback.attachWatcher(watcher);
    mediator.addDataMediatorCallback(callback);
    tv.addTextChangedListener(watcher);
}
 
Example 3
Project: okwallet   File: CurrencyAmountView.java   View Source Code Vote up 5 votes
@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    final Context context = getContext();

    textView = (TextView) getChildAt(0);
    textView.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
    textView.setHintTextColor(lessSignificantColor);
    textView.setHorizontalFadingEdgeEnabled(true);
    textView.setSingleLine();
    setValidateAmount(textView instanceof EditText);
    textView.addTextChangedListener(textViewListener);
    textView.setOnFocusChangeListener(textViewListener);

    contextButton = new View(context) {
        @Override
        protected void onMeasure(final int wMeasureSpec, final int hMeasureSpec) {
            setMeasuredDimension(textView.getCompoundPaddingRight(), textView.getMeasuredHeight());
        }
    };
    final LayoutParams chooseViewParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    chooseViewParams.gravity = Gravity.RIGHT;
    contextButton.setLayoutParams(chooseViewParams);
    this.addView(contextButton);

    updateAppearance();
}
 
Example 4
Project: crossword   File: Main.java   View Source Code Vote up 5 votes
@Override
public void onItemSelected(AdapterView<?> parent, View view,
                           int pos, long id)
{
    // An item was selected. You can retrieve the selected item
    // using parent.getItemAtPosition(pos)
    // Check id
    switch (parent.getId())
    {
    case R.id.spinner:
        String item = (String)parent.getItemAtPosition(pos);

        // Get length
        length = Integer.parseInt(item);

        // Remove the unused slots
        if (letters != null)
        {
            for (int i = 0; i < letters.getChildCount(); i++)
            {
                TextView text = (TextView)letters.getChildAt(i);
                if (i < length)
                    text.setVisibility(View.VISIBLE);

                // Temporarily remove the text change listener to
                // stop unexpected consequences
                else
                {
                    text.setVisibility(View.GONE);
                    text.removeTextChangedListener(this);
                    text.setText("");
                    text.addTextChangedListener(this);
                }
            }
        }
    }
}
 
Example 5
Project: crossword   File: Main.java   View Source Code Vote up 5 votes
@Override
public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id)
{
    // An item was selected. You can retrieve the selected item
    // using parent.getItemAtPosition(pos)
    // Check id
    switch (parent.getId())
    {
    case R.id.list:
        String word = (String)parent.getItemAtPosition(position);
        String s = word.toUpperCase(Locale.getDefault());

        // Fill the letters in the slots and temporarily remove
        // the text change listener to stop unexpected
        // consequences
        for (int i = 0; i < length; i++)
        {
            TextView text = (TextView)letters.getChildAt(i);
            text.removeTextChangedListener(this);
            text.setText(s.substring(i, i + 1));
            text.addTextChangedListener(this);
        }

        // Start the web search
        Intent intent = new Intent(this, SearchActivity.class);
        intent.putExtra(WORD, word);
        startActivity(intent);
    }
}
 
Example 6
Project: crossword   File: Main.java   View Source Code Vote up 5 votes
private void doClear()
{
    // Temporarily remove the text change listener to stop
    // unexpected consequences
    for (int i = 0; i < length; i++)
    {
        TextView text = (TextView)letters.getChildAt(i);
        text.removeTextChangedListener(this);
        text.setText("");
        text.addTextChangedListener(this);
    }
}
 
Example 7
Project: ArscEditor   File: MainActivity.java   View Source Code Vote up 4 votes
@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 8
Project: SuperRecyclerViewAdapter   File: SuperRecyclerHolder.java   View Source Code Vote up 4 votes
public SuperRecyclerHolder addTextChangedListener(@IdRes int viewId, TextWatcher watcher) {
    TextView textView = retrieveView(viewId);
    textView.addTextChangedListener(watcher);
    return this;
}
 
Example 9
Project: BlueTape   File: TextChangedBindingFunction.java   View Source Code Vote up 4 votes
private static void addTextWatcher(TextView textView, @NonNull OnTextChangedListener listener) {
    TextWatcher watcher = TextWatcherAdapter.whenTextChanged(listener);

    textView.addTextChangedListener(watcher);
    textView.setTag(R.id.onTextChangedListener, watcher);
}
 
Example 10
Project: crossword   File: Main.java   View Source Code Vote up 4 votes
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    // Get preferences
    SharedPreferences preferences =
        PreferenceManager.getDefaultSharedPreferences(this);
    dark = preferences.getBoolean(PREF_DARK, false);

    if (dark)
        setTheme(R.style.AppDarkTheme);

    setContentView(R.layout.main);

    // Find views
    spinner = (Spinner)findViewById(R.id.spinner);
    letters = (ViewGroup)findViewById(R.id.letters);
    results = (ListView)findViewById(R.id.list);
    clear = (Button)findViewById(R.id.clear);
    search = (Button)findViewById(R.id.search);

    // Set up listeners
    if (spinner != null)
    {
        spinner.setSelection(LETTERS - 1);
        spinner.setOnItemSelectedListener(this);
    }

    if (clear != null)
        clear.setOnClickListener(this);

    if (search != null)
        search.setOnClickListener(this);

    // Set up letter slots
    if (letters != null)
    {
        for (int i = 0; i < letters.getChildCount(); i++)
        {
            TextView letter = (TextView)letters.getChildAt(i);
            if (i < LETTERS)
                letter.setVisibility(View.VISIBLE);

            else
            {
                letter.setVisibility(View.GONE);
                letter.setText("");
            }

            // Add listeners
            letter.setOnEditorActionListener(this);
            letter.addTextChangedListener(this);
        }
    }

    if (results != null)
        results.setOnItemClickListener(this);

    // Get data instance
    data = Data.getInstance(this);

    // Restore result list
    if (data != null)
        resultList = data.getResultList();

    if (resultList == null)
        resultList = new ArrayList<String>();

    // Create adapter
    adapter =
        new ArrayAdapter<String>(this,
                                 android.R.layout.simple_list_item_1,
                                 resultList);
    if (results != null)
        results.setAdapter(adapter);
}
 
Example 11
Project: stynico   File: TextDrawable.java   View Source Code Vote up 3 votes
/**
 * 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;
    }
}