i have a strange error that i can't solve. The error is : 'equals()' between objects of inconvertible types 'int' and 'TextWatcher'. And this is my code:
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());
}
}
I'm pretty stuck and i dont know what to do. can someone pleas help me?
If your aim is to display the R.string.Good
message if the text in editText_surname
matches R.string.editText_7
then try something like this:
First attach the TextWatcher to editText_surname
:
editText_surname.addTextChangedListener(textWatcher_ans);
In your 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();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.