如何在EditText的文本更改时更改TextView的文本? [英] How to change TextView's text on change of EditText's text?

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

问题描述

我有一个EditText框,用户可以在其中输入输入.用户输入文本时,我需要在TextView(位于EditText下方)中显示输入文本.

I have an EditText box where the user can enter input. I need to display the input text in a TextView (which is placed below the EditText) while the user inputting the text.

示例:

如果用户在EditText框中输入任何字符,则需要在TextView中显示相同的字符.同样,如果用户从EditText删除任何字符,则需要从TextView中删除相同的字符. (最终,我想在更改EditText的文本时更改TextView的文本).我希望我的要求现在很明确.我怎样才能做到这一点?请引导我.

If the user is entering any characters in EditText box, I need to display the same characters in TextView. In the same way, If the user deletes any character from EditText, I need to remove the same character from TextView. (Ultimately, I want to change TextView's text on change of EditText's text). I hope my requirement is clear now. How can I achieve this? Please guide me.

推荐答案

将TextWatcher添加到您的Edittext.在afterTextChanged()中进行操作. http://developer.android.com/reference/android/text/TextWatcher.html

Add TextWatcher to your Edittext. in afterTextChanged() do your operation. http://developer.android.com/reference/android/text/TextWatcher.html

TextWatcher inputTextWatcher = new TextWatcher() {
    public void afterTextChanged(Editable s) { 
                textview.setText(s.toString());
    }
    public void beforeTextChanged(CharSequence s, int start, int count, int after){
    }
    public void onTextChanged(CharSequence s, int start, int before, int count) {
    }
};

editText.addTextChangedListener(inputTextWatcher);

这篇关于如何在EditText的文本更改时更改TextView的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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