我有一个奇怪的错误,我无法解决。错误是:'不可逆类型'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());
}
}
我很困难,我不知道该怎么做。 有人请求帮助我吗?
答案 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();
}
}