I'm using RxBinding and creating a subscription in RecyclerView adapter in onBindViewHolder method, which reuses items. Is there any simple way to check if I already assigned subscriber to an EditText object and if so delete that subscription?
My code looks like this
public void onBindViewHolder(final ItemViewHolder holder, int position) {
holder.text.setText(mProvider.get(position).text);
Subscription textSub = RxTextView.textChanges(holder.text).subscribe(new Action1<CharSequence>() {
@Override
public void call(CharSequence charSequence) {
...
}
});
subscriptions.add(textSub);
}
Is there anyway to check if I already assigned subscriber to an EditText object and if so delete that subscription?
you could keep it as class member. Eg
Subscription textSub = Subscriptions.unsubscribed();
and then
public void onBindViewHolder(final ItemViewHolder holder, final int position) {
holder.text.setText(mProvider.get(position).text);
textSub.unsubscribe();
textSub = RxTextView.textChanges(holder.text).subscribe(new Action1<CharSequence>() {
@Override
public void call(CharSequence charSequence) {
...
}
});
}
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.