I have got this error on Android Studio IDE. It says
Incompatible types; Required android.widget.EditText and Found java.lang.String
@Override
public void afterTextChanged(Editable s) {
if (editabletext.length() == 8) {
editabletext = editabletext.getText().toString().replaceAll("([0-9]{4})([0-9]{4})", "$1-$2")
}
}
editabletext
is an EditText and replaceAll
returns a String. What the compiler says is that you can't assign a String
to an EditText
. You could change your code this way:
if(editabletext.length() == 8){
String tmp = editabletext.getText().toString().replaceAll("([0-9]{4})([0-9]{4})", "$1-$2");
editabletext.setText(tmp);
}
Replace
editabletext= editabletext.getText().toString().replaceAll("([0-9]{4})([0-9]{4})", "$1-$2")
with
editabletext.setText(editabletext.getText().toString().replaceAll("([0-9]{4})([0-9]{4})", "$1-$2"))
as editabletext
is of type Editable
and replaceAll
returns a String
find the definition of "editabletext" and change the type from EditText to String