gpt4 book ai didi

java - Rxjava2 distinctUntilChanged() 第一次后无法正常工作

转载 作者:行者123 更新时间:2023-11-29 06:27:55 25 4
gpt4 key购买 nike

我正在尝试使用 .distinctUntilChanged() 并且它在第一次后没有将值传递给 switchmap()

RxTextView.textChanges(etUserQuery).debounce(300, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread()).filter(charSequence -> {
if (charSequence.toString().isEmpty()) {
etUserQuery.setHint("Please type username");
return false;
} else
return true;
}).distinctUntilChanged()
.switchMap(charSequence -> vm.dataFromNetwork(charSequence.toString()))
.subscribe(fetchUserResponce -> {
noDataText.setVisibility(fetchUserResponce.getItems().size() == 0 ? View.VISIBLE : View.GONE);
mUsersListAdapter.updateData(fetchUserResponce.getItems());
}));

使用 .distinctUntilChanged() 的地方是否正确?

最佳答案

来自评论:

textChanges 给你的 CharSequence 是可变的,在传递之前应该变成 String

textChanges 为您提供相同的 CharSequence 引用,distinctUntilChange 依赖于 Object.equals() 会找到它始终等于自身。

关于java - Rxjava2 distinctUntilChanged() 第一次后无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47772357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com