3

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);
}
M Tomczynski
  • 15,099
  • 1
  • 15
  • 25

1 Answers1

3

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. E.g.

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) {
               ...
          }
      });
}
Ziem
  • 6,579
  • 8
  • 53
  • 86
Blackbelt
  • 156,034
  • 29
  • 297
  • 305