I'm just playing around with Kotlin on my project and I came to strange problem... When trying to convert custom EditText Android studio stops responding. When I tried to convert it part by part, it stops responding when converting this piece of code:
private TextWatcher editor = new TextWatcher() {
long newMicro = 0;
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
s = s.toString().replace(".", "")
.replace(",", "")
.replace("$", "");
try {
newMicro = Long.parseLong(s.toString());
} catch (Exception e) {
newMicro = 0;
}
}
@Override
public void afterTextChanged(Editable editable) {
removeTextChangedListener(editor);
setMicroUnits(newMicro);
addTextChangedListener(editor);
}
};
Have you experienced such a behavior? I'm unable to reimplement this TextWatcher in Kotlin since I cannot perform neither
CharSequence.toString().replace()
nor
Any idea how to implement custom TextWatcher in Kotlin? This is code I've prepared:
val editor = object : TextWatcher {
override fun afterTextChanged(p0: Editable?) {
}
override fun beforeTextChanged(p0: CharSequence, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(p0: CharSequence, p1: Int, p2: Int, p3: Int) {
}
}
Edit: Problem occurs while working with kotlin version 1.1.2-4 on Android Studio 3 Preview 6