Created
August 1, 2018 00:30
-
-
Save luthfihariz/8df6d703025ad74ca57f0d008dcfddc2 to your computer and use it in GitHub Desktop.
Observing LiveData
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EventListActivity : BaseActivity(){ | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_event_list) | |
val viewModel = ViewModelProviders.of(this).get(EventListViewModel::class.java) | |
// setup recyclerview | |
rvListOfKajian.layoutManager = LinearLayoutManager(this) | |
val adapter = EventListAdapter() | |
rvListOfKajian.adapter = adapter | |
// observe data from viewmodel | |
viewModel.eventList.observe(this@EventListActivity, Observer<List<Event>> { t -> adapter.update(t) }) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment