如何获得TextWatcher方法方面有何看法? [英] How to get the View in TextWatcher method context?

查看:198
本文介绍了如何获得TextWatcher方法方面有何看法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个处理程序,它是一个 TextWatcher ,我不知道如何让查看已更改文本

下面是我的处理程序:

  TextWatcher处理程序=新TextWatcher(){    @覆盖
    公共无效onTextChanged(CharSequence中,诠释开始,诠释之前,诠释计数){
        // TODO自动生成方法存根    }    @覆盖
    公共无效beforeTextChanged(CharSequence中,诠释开始,诠释计数后INT){
        oldText = s.toString();
    }    @覆盖
    公共无效afterTextChanged(编辑S){
        //v.setText(\"afterTextChanged);
    }
};

请注意注释的一部分,这就是我想要的东西,得到查看的EditText 已触发的情况下,文本更改后更改文本。

我怎样才能达到的 afterTextChanged 的事件这里面 .setText()的方法? (像onClick事件的看法是 v


解决方案

 公共静态类MyTextWatcher实现TextWatcher {    私人的EditText mEditText;    公共MyTextWatcher(EditText上EDITTEXT){
        mEditText = EDITTEXT;
    }    @覆盖
    公共无效onTextChanged(CharSequence中,诠释开始,诠释之前,诠释计数){
        oldText = mEditText.toString();
    }
    ....
}

通过添加:

  mFirstEditText.addTextChangedListener(新MyTextWatcher(mFirstEditText));

I have a handler that is a TextWatcher and i dont know how to get the View that has changed text.

Here is my handler:

TextWatcher handler = new TextWatcher() {

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        // TODO Auto-generated method stub

    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        oldText = s.toString();
    }

    @Override
    public void afterTextChanged(Editable s) {
        //v.setText("afterTextChanged");
    }
};

Note the commented part, that is what i want, to get the View from the EditText that has triggered the event, to change the text after the text was changed.

How i can reach this .setText() method inside the afterTextChanged event? (Like onClick event that view is v)

解决方案

public static class MyTextWatcher implements TextWatcher {

    private EditText mEditText;

    public MyTextWatcher(EditText editText) {
        mEditText = editText;
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        oldText = mEditText.toString();
    }
    ....
}

Add it with:

    mFirstEditText.addTextChangedListener(new MyTextWatcher(mFirstEditText));

这篇关于如何获得TextWatcher方法方面有何看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆