Newer
Older
DevRealm / app / src / main / java / jackall / devrealm / activity / MainActivity.kt
MatsumotoKeiju on 8 Nov 2017 803 bytes [add] MainViewModel
  1. package jackall.devrealm.activity
  2.  
  3. import android.arch.lifecycle.ViewModelProviders
  4. import android.databinding.DataBindingUtil
  5. import android.os.Bundle
  6. import android.support.v7.app.AppCompatActivity
  7. import jackall.devrealm.R
  8. import jackall.devrealm.databinding.ActivityMainBinding
  9. import jackall.devrealm.viewmodel.MainViewModel
  10.  
  11. class MainActivity : AppCompatActivity() {
  12.  
  13. val binding by lazy { DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main) }
  14. val mainViewModel by lazy { ViewModelProviders.of(this, MainViewModel.Factory()).get(MainViewModel::class.java) }
  15.  
  16. override fun onCreate(savedInstanceState: Bundle?) {
  17. super.onCreate(savedInstanceState)
  18. binding.mainViewModel = mainViewModel
  19. lifecycle.addObserver(mainViewModel)
  20. }
  21. }