RxBus-Kotlin-Example Using RxBus in Kotlin Projects
In this RxBus-Kotlin example, you will learn how to integrate RxBus into your project and how to use it for event publishing. Here's the step-by-step guide:
- Add the required dependencies and classes to your project.
- Once integrated, you can start publishing events using
RxBus.publish(RxEvent.EventAddPerson(etPersonName.text.toString()))
.
MainActivity class implementation:
class MainActivity : AppCompatActivity() {
private lateinit var disposable: Disposable
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
disposable = RxBus.listen(RxEvent.EventAddPerson::class.java)
.subscribe { event ->
// Handle the event
}
}
}
227.38KB
文件大小:
评论区