I'm using a RecyclerView that contains items containing a EditText each one.
I add a TextWatcher in this EditText in the ViewHolder constructor. This text watcher call: adapter.notifyItemChanged()
When bind views, I do:
edittext.setText("value");
So text changed event is fired, but I don't want that beacuse I get
java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling
I want that event is fired only when user changes the text manually. Is there a way to differentiate this events?
I could remove and add again the TextWatcher each time views are binded but I'd like find another better solution.
Instead of setting the TextWatcher in the ViewHolder constructor, you can do that while binding the view, right after the setText() call, avoiding the problem you are experiencing.
So:
edittext.setText("value");
edittext.setTextWatcher(new TextWatcher(..
This way the TextWatcher will not immediately fire an event because it didn't yet exist when the initial value was set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With