• <bdo id='qyqgv'></bdo><ul id='qyqgv'></ul>

    <small id='qyqgv'></small><noframes id='qyqgv'>

  • <legend id='qyqgv'><style id='qyqgv'><dir id='qyqgv'><q id='qyqgv'></q></dir></style></legend>

        <i id='qyqgv'><tr id='qyqgv'><dt id='qyqgv'><q id='qyqgv'><span id='qyqgv'><b id='qyqgv'><form id='qyqgv'><ins id='qyqgv'></ins><ul id='qyqgv'></ul><sub id='qyqgv'></sub></form><legend id='qyqgv'></legend><bdo id='qyqgv'><pre id='qyqgv'><center id='qyqgv'></center></pre></bdo></b><th id='qyqgv'></th></span></q></dt></tr></i><div id='qyqgv'><tfoot id='qyqgv'></tfoot><dl id='qyqgv'><fieldset id='qyqgv'></fieldset></dl></div>

        <tfoot id='qyqgv'></tfoot>
      1. RxTextView.textChanges 与 Edittext 上的 setText

        时间:2023-10-01
        • <i id='BWrtm'><tr id='BWrtm'><dt id='BWrtm'><q id='BWrtm'><span id='BWrtm'><b id='BWrtm'><form id='BWrtm'><ins id='BWrtm'></ins><ul id='BWrtm'></ul><sub id='BWrtm'></sub></form><legend id='BWrtm'></legend><bdo id='BWrtm'><pre id='BWrtm'><center id='BWrtm'></center></pre></bdo></b><th id='BWrtm'></th></span></q></dt></tr></i><div id='BWrtm'><tfoot id='BWrtm'></tfoot><dl id='BWrtm'><fieldset id='BWrtm'></fieldset></dl></div>

              <tbody id='BWrtm'></tbody>

            <small id='BWrtm'></small><noframes id='BWrtm'>

            1. <tfoot id='BWrtm'></tfoot>

                <bdo id='BWrtm'></bdo><ul id='BWrtm'></ul>

                  <legend id='BWrtm'><style id='BWrtm'><dir id='BWrtm'><q id='BWrtm'></q></dir></style></legend>

                1. 本文介绍了RxTextView.textChanges 与 Edittext 上的 setText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  RxTextView.textChanges(editText)
                                  .map(CharSequence::toString)
                                  .debounce(200, TimeUnit.MILLISECONDS)
                                  .observeOn(AndroidSchedulers.mainThread())
                                  .subscribe(input -> {
                                     output = //...do something with input
                                     editText.setText(ouput)
                                   }));
                  

                  当我 setText(output) 它进入循环.要设置文本,我首先需要删除侦听器,然后再次设置侦听器.如何使用 RxJava 做到这一点?

                  When I setText(output) it goes in loop. To set the text I first need to remove listener and then set listener again. How can I do this using RxJava?

                  推荐答案

                  当我 setText(output) 它进入循环.要设置文本,我首先需要删除侦听器,然后再次设置侦听器.如何使用 RxJava 做到这一点?

                  When I setText(output) it goes in loop. To set the text I first need to remove listener and then set listener again. How can I do this using RxJava?

                  为了满足要求,我设法扩展了 RxBinding 源代码,如下所示.

                  To meet the requirement I managed to extend the RxBinding source code as follows.

                  EditableTextViewTextObservable.java:

                  public class EditableTextViewTextObservable extends InitialValueObservable<CharSequence> {
                      private final TextView view;
                  
                      EditableTextViewTextObservable(TextView view) {
                          this.view = view;
                      }
                  
                      @Override
                      protected void subscribeListener(Observer<? super CharSequence> observer) {
                          EditableTextViewTextObservable.Listener listener = new EditableTextViewTextObservable.Listener(view, observer);
                          observer.onSubscribe(listener);
                          view.addTextChangedListener(listener);
                      }
                  
                      @Override protected CharSequence getInitialValue() {
                          return view.getText();
                      }
                  
                      final static class Listener extends MainThreadDisposable implements TextWatcher {
                          private final TextView view;
                          private final Observer<? super CharSequence> observer;
                  
                          Listener(TextView view, Observer<? super CharSequence> observer) {
                              this.view = view;
                              this.observer = observer;
                          }
                  
                          @Override
                          public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                          }
                  
                          @Override
                          public void onTextChanged(CharSequence s, int start, int before, int count) {
                          }
                  
                          @Override
                          public void afterTextChanged(Editable s) {
                              if (!isDisposed()) {
                                  view.removeTextChangedListener(this);
                                  observer.onNext(s);
                                  view.addTextChangedListener(this);
                              }
                          }
                  
                          @Override
                          protected void onDispose() {
                              view.removeTextChangedListener(this);
                          }
                      }
                  }
                  

                  EditableRxTextView.java:

                  public final class EditableRxTextView {
                      @CheckResult
                      @NonNull
                      public static InitialValueObservable<CharSequence> textChanges(@NonNull TextView view) {
                          return new EditableTextViewTextObservable(view);
                      }
                  }
                  

                  用法:

                  EditableRxTextView.textChanges(editText)
                              .map(CharSequence::toString)
                              .debounce(200, TimeUnit.MILLISECONDS)
                              .observeOn(AndroidSchedulers.mainThread())
                              .subscribe(input -> {
                                 output = //...do something with input
                                 editText.setText(ouput)
                               }));
                  

                  这篇关于RxTextView.textChanges 与 Edittext 上的 setText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何收听 EditText? 下一篇:Android Thread 修改 EditText

                  相关文章

                  最新文章

                      <bdo id='wtEz9'></bdo><ul id='wtEz9'></ul>

                    <small id='wtEz9'></small><noframes id='wtEz9'>

                  1. <i id='wtEz9'><tr id='wtEz9'><dt id='wtEz9'><q id='wtEz9'><span id='wtEz9'><b id='wtEz9'><form id='wtEz9'><ins id='wtEz9'></ins><ul id='wtEz9'></ul><sub id='wtEz9'></sub></form><legend id='wtEz9'></legend><bdo id='wtEz9'><pre id='wtEz9'><center id='wtEz9'></center></pre></bdo></b><th id='wtEz9'></th></span></q></dt></tr></i><div id='wtEz9'><tfoot id='wtEz9'></tfoot><dl id='wtEz9'><fieldset id='wtEz9'></fieldset></dl></div>

                    <legend id='wtEz9'><style id='wtEz9'><dir id='wtEz9'><q id='wtEz9'></q></dir></style></legend>
                      <tfoot id='wtEz9'></tfoot>