gpt4 book ai didi

java - '等于( )' between objects of inconvertible types ' int' 和 'TextWatcher' 错误

转载 作者:行者123 更新时间:2023-12-01 10:36:20 27 4
gpt4 key购买 nike

我有一个无法解决的奇怪错误。错误是:不可转换类型“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());
}
}

我很困惑,我不知道该怎么办。有人可以帮助我吗?

最佳答案

如果您的目标是在 editText_surname 中的文本与 R.string.editText_7 匹配时显示 R.string.Good 消息,请尝试像这样的东西:

首先将 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();
}
}

关于java - '等于( )' between objects of inconvertible types ' int' 和 'TextWatcher' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34707546/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com