Skip to content

Instantly share code, notes, and snippets.

@nsadisha
Created November 1, 2022 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nsadisha/5d019a9d29d8ac935af36f169bcdf8cf to your computer and use it in GitHub Desktop.
Save nsadisha/5d019a9d29d8ac935af36f169bcdf8cf to your computer and use it in GitHub Desktop.
package com.nsadisha.mvvmtest_2.viewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.nsadisha.mvvmtest_2.model.Counter
class FirstViewModel: ViewModel() {
private var _data = MutableLiveData<Counter>().apply {
value = Counter(0)
}
val data: LiveData<Counter> = _data
fun increase(){
_data.value = _data.value.apply {
this?.increment()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment