RxJava/RxBinding - 检查订阅是否存在
RxJava/RxBinding - check if subscription exists
我正在使用 RxBinding 并在 RecyclerView 适配器中的 onBindViewHolder 方法中创建订阅,它会重用项目。有什么简单的方法可以检查我是否已将订阅者分配给 EditText 对象,如果是,则删除该订阅?
我的代码是这样的
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?
您可以将其保留为 class 会员。例如
Subscription textSub = Subscriptions.unsubscribed();
然后
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) {
...
}
});
}
我正在使用 RxBinding 并在 RecyclerView 适配器中的 onBindViewHolder 方法中创建订阅,它会重用项目。有什么简单的方法可以检查我是否已将订阅者分配给 EditText 对象,如果是,则删除该订阅?
我的代码是这样的
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?
您可以将其保留为 class 会员。例如
Subscription textSub = Subscriptions.unsubscribed();
然后
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) {
...
}
});
}