Guest User

Untitled

a guest
Jan 17th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. class MainActivity : AppCompatActivity() {
  2.  
  3. override fun onCreate(savedInstanceState: Bundle?) {
  4. super.onCreate(savedInstanceState)
  5. setContentView(R.layout.activity_main)
  6. observeEvents()
  7. RxBus.instance.publish(FRAGMENT_ONE_TAG)
  8. }
  9.  
  10. private fun observeEvents() {
  11. RxBus.instance.subscribe {
  12. when (it as String) {
  13. FRAGMENT_ONE_TAG -> {
  14. supportFragmentManager.transaction {
  15. replace(R.id.frame_layout, FragmentOne(), FRAGMENT_ONE_TAG)
  16. }
  17. }
  18. FRAGMENT_TWO_TAG -> {
  19. supportFragmentManager.transaction {
  20. replace(R.id.frame_layout, FragmentTwo(), FRAGMENT_TWO_TAG)
  21. }
  22. }
  23. FINISH_APP_TAG -> this.finish()
  24. }
  25. }
  26. }
  27.  
  28. companion object {
  29. const val FRAGMENT_ONE_TAG = "FRAGMENT_ONE"
  30. const val FRAGMENT_TWO_TAG = "FRAGMENT_TWO"
  31. const val FINISH_APP_TAG = "FINISH_APP"
  32. }
  33.  
  34. }
Add Comment
Please, Sign In to add comment