Observable - 订阅两种方法

时间:2016-10-31 11:25:08

标签: java android rx-java

我有Observable喜欢:

  Observable<Integer> dropdownChange =     ReactiveUIObservables.selectionChange(myDropdown)

我现在有:

  LifecycleObservable.bindFragmentLifecycle(lifecycle(), dropdownChange)
    .ObserveOn(AndroidSchedulers.mainThread))
    .SubscribeOn(AndroidSchedulers.mainThread())
    .subscribe(this::onDropdownChange);

它正在运行,现在DropdownChange我希望在selectionChange上运行另一种方法。怎么做?

2 个答案:

答案 0 :(得分:1)

您可以使用subscribe来调用多种方法。 E.g。

subscribe(myValue -> {
      onDropdownChange(myValue); 
      // call the other method 
});

答案 1 :(得分:0)

如果您的所有订阅者都需要接收相同的活动,则可以使用ConnectableObservable。在您调用.connect()。

之前,不会发出事件
Option Explicit

Sub main()
    Dim word As String

    word = GetRandomWord(Worksheets("Sheet2").Range("A1:B200")) '<--| get content of a random cell in passed range
    Worksheets("Sheet1").Range("a1").Resize(2 * Len(word) - 1).Value = Application.Transpose(SeparatedChars(word)) '<--| write it down from given worksheet cell A1 down skipping every two cells
End Sub

Function SeparatedChars(strng As String) As Variant
    Dim i As Long

    ReDim chars(0 To Len(strng) - 1) As String '<--| size a 'String' array to the length of passed word
    For i = 1 To Len(strng)
        chars(i - 1) = Mid$(strng, i, 1) '<--| fill array elements with word single characters
    Next
    SeparatedChars = Split(Join(chars, "  "), " ") '<--| return an array whose elements are those of the 'String' array and interposed spaces
End Function

Function GetRandomWord(rng As Range) As String
    Randomize
    GetRandomWord = rng.Cells(Int((rng.Count) * Rnd() + 1)).Text
End Function