gpt4 book ai didi

android - RxBinding TextChanges 不会继续发出文本更改

转载 作者:行者123 更新时间:2023-11-29 16:45:52 25 4
gpt4 key购买 nike

试图找出为什么 RxTextView.textChanges 只发出初始值。我的理解是它应该向下游订阅发送所有新的文本更改。

这是代码

    public class SignupFragment extends Fragment {

@BindView(R.id.text_name) EditText txtName;
@BindView(R.id.text_email) EditText txtEmail;
@BindView(R.id.text_password) EditText txtPassword;
@BindView(R.id.text_confirm_password) EditText txtConfirmPassword;
@BindView(R.id.btn_signup) Button btnSignup;
SignupViewModel viewModel;
private CompositeDisposable disposables;

FragmentSignupBinding binding;
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_signup, container, false);
ButterKnife.bind(this, view);
this.disposables = new CompositeDisposable();

RxTextView.textChanges(txtEmail)
.subscribe(new Observer<CharSequence>() {
@Override
public void onSubscribe(Disposable d) {

}

@Override
public void onNext(CharSequence charSequence) {
Log.d("Subscription", charSequence.toString());
}

@Override
public void onError(Throwable e) {

}

@Override
public void onComplete() {
Log.d("Subscription", "On Complete");
}
});

viewModel = ViewModelProviders.of(this).get(SignupViewModel.class);
viewModel.applyInputs(RxTextView.textChanges(txtName),
RxTextView.textChanges(txtEmail),
RxTextView.textChanges(txtPassword),
RxTextView.textChanges(txtConfirmPassword),
RxView.clicks(btnSignup));


Disposable validInputs =
viewModel.validInputs()
.doOnNext(new Consumer<Boolean>() {
@SuppressLint("TimberArgCount")
@Override
public void accept(Boolean aBoolean) throws Exception {
Timber.d("Valid inputs: %b", aBoolean.booleanValue());
}
})
.subscribe(RxView.visibility(btnSignup));

disposables.add(validInputs);

FragmentSignupBinding binding = FragmentSignupBinding.inflate(inflater, container, false);
return binding.getRoot();
}

@Override
public void onDestroy() {
super.onDestroy();
this.disposables.dispose();
}
}

这之前被编辑过以关注我认为的问题所在。这是现在的完整画面。

最佳答案

我没有正确处理 fragment 数据绑定(bind)。在代码的这一点上,它甚至没有必要。我没有意识到设置会影响 RxBindingings。

以下代码已损坏...

 @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_signup, container, false);
...

FragmentSignupBinding binding = FragmentSignupBinding.inflate(inflater, container, false);
return binding.getRoot();
}

以下代码现在可以工作....

    @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
FragmentSignupBinding binding = DataBindingUtil.inflate(inflater, R.layout.fragment_signup, container, false);
View view = binding.getRoot();
ButterKnife.bind(this, view);
this.disposables = new CompositeDisposable();
....
return view;
}

关于android - RxBinding TextChanges 不会继续发出文本更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48127239/

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