Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Y元素中第一个X元素的组合测试_Android_Rx Java_Rx Android_Rx Binding - Fatal编程技术网

Android Y元素中第一个X元素的组合测试

Android Y元素中第一个X元素的组合测试,android,rx-java,rx-android,rx-binding,Android,Rx Java,Rx Android,Rx Binding,我的观点有三个场,它们共同构成一个方程。我想要实现的是,只要用户填写3个字段中的2个,我就计算剩下的一个 我所拥有的: mObservableEditTextA = RxTextView.textChanges(mEditTextA); mObservableEditTextB = RxTextView.textChanges(mEditTextB); mObservableEditTextC = RxTextView.textChanges(mEditTextC); 我试图为每一对字段合并其

我的观点有三个场,它们共同构成一个方程。我想要实现的是,只要用户填写3个字段中的2个,我就计算剩下的一个

我所拥有的:

mObservableEditTextA = RxTextView.textChanges(mEditTextA);
mObservableEditTextB = RxTextView.textChanges(mEditTextB);
mObservableEditTextC = RxTextView.textChanges(mEditTextC);
我试图为每一对字段合并其他两个字段中的最新字段,但没有成功

Observable.combineLatest(mObservableEditTextA, mObservableEditTextB, (a, b) -> /* My action here */);
Observable.combineLatest(mObservableEditTextA, mObservableEditTextC, (a, c) -> /* My action here */);
Observable.combineLatest(mObservableEditTextB, mObservableEditTextC, (b, c) -> /* My action here */);

如何实现此行为?

可能有更好的方法,但您可以为每个事件附加一个发射时间戳,确定其中哪一个是最后一个,然后发射其余的。通过可观察事件(字段)来识别这些事件,并通过列表中缺少的元素来决定

mObservableEditTextA = RxTextView.textChanges(mEditTextA)
    .debounce(500, TimeUnit.MILLISECONDS) // So we don't flood the heap with lots of object construction, creating performance overhead due to garbage collection
    .map(text -> Pair.create(new Date(), text));
mObservableEditTextB = RxTextView.textChanges(mEditTextB)
    .debounce(500, TimeUnit.MILLISECONDS)
    .map(text -> Pair.create(new Date(), text));
mObservableEditTextC = RxTextView.textChanges(mEditTextC)
    .debounce(500, TimeUnit.MILLISECONDS)
    .map(text -> Pair.create(new Date(), text));

Observable.combineLatest(mObservableEditTextA, mObservableEditTextB, mObservableEditTextC, (fieldAPair, fieldBPair, fieldCPair) -> {
        firstField = ...;
        secondField = ...;
        // from timestamps determine which of the fields emitted last and return the other two with identifiers
        return Arrays.asList(Pair.create(firstFieldIdentifier, firstField), Pair.create(secondFieldIdentifier, secondField));
    })
    .subscribe(result -> {
        /* result is always a list of 2 items, more specifically 
           pairs of an identification in first position and new text 
           in the second. 

           Here you can look for the missing field in the list and 
           compute it from the other two */
    })
确定要计算哪一个的逻辑在此重复。我这样做只是因为不必将这些对象包装到新对象中,嵌套对将失去可读性

但是,您可以将列表中的位置视为字段的标识符,尽管这很容易出错


这些方法中的任何一种都会将确定逻辑从subscriber和CombineTest运算符移到subscriber本身。您的呼叫。

可能有更好的方法,但您可以在每个事件上附加发射时间戳,确定其中哪一个是最后一个,然后发射其余的。通过可观察事件(字段)来识别这些事件,并通过列表中缺少的元素来决定

mObservableEditTextA = RxTextView.textChanges(mEditTextA)
    .debounce(500, TimeUnit.MILLISECONDS) // So we don't flood the heap with lots of object construction, creating performance overhead due to garbage collection
    .map(text -> Pair.create(new Date(), text));
mObservableEditTextB = RxTextView.textChanges(mEditTextB)
    .debounce(500, TimeUnit.MILLISECONDS)
    .map(text -> Pair.create(new Date(), text));
mObservableEditTextC = RxTextView.textChanges(mEditTextC)
    .debounce(500, TimeUnit.MILLISECONDS)
    .map(text -> Pair.create(new Date(), text));

Observable.combineLatest(mObservableEditTextA, mObservableEditTextB, mObservableEditTextC, (fieldAPair, fieldBPair, fieldCPair) -> {
        firstField = ...;
        secondField = ...;
        // from timestamps determine which of the fields emitted last and return the other two with identifiers
        return Arrays.asList(Pair.create(firstFieldIdentifier, firstField), Pair.create(secondFieldIdentifier, secondField));
    })
    .subscribe(result -> {
        /* result is always a list of 2 items, more specifically 
           pairs of an identification in first position and new text 
           in the second. 

           Here you can look for the missing field in the list and 
           compute it from the other two */
    })
确定要计算哪一个的逻辑在此重复。我这样做只是因为不必将这些对象包装到新对象中,嵌套对将失去可读性

但是,您可以将列表中的位置视为字段的标识符,尽管这很容易出错

这些方法中的任何一种都会将确定逻辑从subscriber和CombineTest运算符移到subscriber本身。你的电话