Android rxjava / rxbinding – check if the subscription exists
•
Android
I am using rxbinding and creating a subscription in the recyclerview adapter of the onbindviewholder method. The subscription is a reusable item. Is there a simple way to check whether the subscriber has been assigned to the EditText object and delete the subscriber if it has been deleted?
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);
}
resolvent:
You can keep it as a class member. For example
Subscription textSub = Subscriptions.unsubscribed();
next
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 content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码