For those who know EditText and (scrolling) RecyclerView, how do I find out whether an edittext has been edited? RecyclerView loads data from myList. when you scroll, TextWatcher updates itself to save the position inside myList that the edittext is currently showing. The code here:
public class CustomTextWatcher3 implements TextWatcher {
private int position;
public void updatePosition(int position) {
this.position = position;
}
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
Double x;
if (matchPattern.isDouble(charSequence.toString())) {
x = Double.valueOf(charSequence.toString());
} else {
x = 0.0;
}
myList.get(position).setValue(x);
}
@Override
public void afterTextChanged(Editable editable) {
}
}
One way to find out whether it has been changed is by checking if
myList.get(position).getValue()
is equal to the double value of
charSequence.toString() inside onTextChanged()
but that (OnTextChanged) would get called every time the RecyclerView gets scrolled (the EditText gets recycled, doesn't matter if you're actually editing the text or not) which could be very expensive. The problem with that is myList ALWAYS GETS UPDATED WHEN YOU SCROLL
myList.get(position).setWasted(x);
doesn't matter if you're editing it or not. and if you were to check if the text inside the edittext is the same as the one in myList, that's frikkin ugly.
Any alternatives? Suggestions? Anything?
With Love, Jack Smother