如何在android中使用TextWatcher?

Nar*_*Pal 0 android

我有一个自定义ListView,其中包含一个TextView(Of数字)和一个EditText.在标题之外我有一个TextView.

我的任务是,当我要在任何editText中输入任何数字然后在标题 textView上它应该显示editText乘法值*textView的ListView的值.

然后,如果我在任何其他editText中输入任何其他数字,那么计算将与前一个相同,比如说editText的乘法值*textView ListView的行值+ editText的乘法值*textView ListView行的值并显示这个标题textView上的新值.如果更改任何editText的值,那么旧位置的先前值应该在相应位置的新值上更新. 我知道所有这些工作将在textwatcher中发生,但不知道如何?你能帮助我吗???

Sre*_*v R 15

我想这段代码会帮助你......

EditText etSearchBar = (EditText)findViewById(Your_id);

    etSearchBar.addTextChangedListener(textwatcher);

    private TextWatcher textwatcher = new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {

            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {


            }

            @Override
            public void afterTextChanged(Editable s) {

                //Do what ever you want here after you enter each text
            }
        };
Run Code Online (Sandbox Code Playgroud)