不可转换类型'int'和'TextWatcher'错误

时间:2016-01-10 15:59:34

标签: java android

我有一个奇怪的错误,我无法解决。错误是:'不可逆类型'int'和'TextWatcher'的对象之间的'equals()'。这是我的代码:

if( textWatcher_ans.equals(R.string.editText_7)){
    Toast.makeText(getApplication().getBaseContext(),
                   (R.string.Good),Toast.LENGTH_SHORT).show();
}

            private final TextWatcher textWatcher_ans = new TextWatcher(){
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                textView_name.setVisibility(View.VISIBLE);
            }
            public void afterTextChanged(Editable s) {
                if (s.length() == 0) {
                    textView_name.setVisibility(View.GONE);
                } else {
                    textView_name.setText("You have entered : " + editText_surname.getText());
                }
            }

我很困难,我不知道该怎么做。 有人请求帮助我吗?

1 个答案:

答案 0 :(得分:1)

如果R.string.Good中的文字与editText_surname匹配,您的目的是显示R.string.editText_7消息,请尝试以下操作:

首先将TextWatcher附加到editText_surname

editText_surname.addTextChangedListener(textWatcher_ans);

afterTextChangedMethod

public void afterTextChanged(Editable s) {
    if (s.length() == 0) {
        textView_name.setVisibility(View.GONE);
     } else {
        textView_name.setText("You have entered : " + s.toString());
     }

    if (s.toString().equals(context.getString(R.string.editText_7)) {
        Toast.makeText(getApplication().getBaseContext(),
               (R.string.Good),Toast.LENGTH_SHORT).show();
    }
}