• <small id='Ihbn8'></small><noframes id='Ihbn8'>

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

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

        • <bdo id='Ihbn8'></bdo><ul id='Ihbn8'></ul>
      1. RxTextView.textChanges 与 Edittext 上的 setText

        RxTextView.textChanges with setText on Edittext(RxTextView.textChanges 与 Edittext 上的 setText)

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

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

              <tbody id='bQnaq'></tbody>
              <legend id='bQnaq'><style id='bQnaq'><dir id='bQnaq'><q id='bQnaq'></q></dir></style></legend><tfoot id='bQnaq'></tfoot>

                  本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                    <tbody id='D3CM6'></tbody>
                      <bdo id='D3CM6'></bdo><ul id='D3CM6'></ul>
                      <tfoot id='D3CM6'></tfoot>

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

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