Skip to content

Instantly share code, notes, and snippets.

@luthfihariz
Created August 1, 2018 00:30
Show Gist options
  • Save luthfihariz/8df6d703025ad74ca57f0d008dcfddc2 to your computer and use it in GitHub Desktop.
Save luthfihariz/8df6d703025ad74ca57f0d008dcfddc2 to your computer and use it in GitHub Desktop.
Observing LiveData
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