Skip to content

Instantly share code, notes, and snippets.

@jjjlyn
Last active May 19, 2020 02:38
Show Gist options
  • Save jjjlyn/05df4111bfcce4116d1a77ac3e95fd2a to your computer and use it in GitHub Desktop.
Save jjjlyn/05df4111bfcce4116d1a77ac3e95fd2a to your computer and use it in GitHub Desktop.
class HistoryFragment : BaseFragment() {
private lateinit var mHistoryViewModel : HistoryViewModel
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
mHistoryViewModel = ViewModelProvider(this).get(HistoryViewModel::class.java)
subscribeObservers()
}
fun subscribeObservers(){
mHistoryViewModel.loadHistory().observe(viewLifecycleOwner, Observer {
// your code
})
}
fun showDatePickerDialog(){
// your code for selecting date
// val date : String = 선택한 date
mHistoryViewModel.setDate(date)
// 이 구간에서 mDate로 선언된 Livedata value가 변경되어 loadHistory()도 Callback으로 같이 호출된다.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment