Creating Observable from normal Java events

前端 未结 4 2074
花落未央
花落未央 2020-12-30 00:15

What is the best way to create an Rx-Java Observable from the classical Java event pattern? That is, given

class FooEvent { ... }

interface Foo         


        
4条回答
  •  执念已碎
    2020-12-30 00:42

    I don't think there's a way to create a generic observable for every possible event, but you can certainly use them wherever you need.

    The RxJava source has some handy examples of how to create observables from mouse events, button events, etc. Take a look at this class, which creates them from KeyEvents: KeyEventSource.java.

提交回复
热议问题