android-RxJava / RxBinding-检查订阅是否存在
作者:互联网
我正在使用RxBinding并在onBindViewHolder方法的RecyclerView适配器中创建订阅,该订阅可重用项目.有没有简单的方法来检查是否已将订户分配给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?
您可以将其保留为班级成员.例如.
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) {
...
}
});
}
标签:android-recyclerview,rx-java,android,rx-binding 来源: https://codeday.me/bug/20191118/2024643.html