Last active
January 23, 2021 00:50
-
-
Save lisamariewatkins/523cd83eba6d9c283a75b097bef93792 to your computer and use it in GitHub Desktop.
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 MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
val model: MainViewModel by viewModels() | |
button.setOnClickListener { | |
model.onButtonClick() | |
} | |
model.displayText.observe(this, Observer { text -> | |
text_view.text = text | |
}) | |
} | |
} | |
class MainViewModel : ViewModel() { | |
private val _displayText = MutableLiveData<String>() | |
val displayText: LiveData<String> | |
get() = _displayText | |
fun onButtonClick() { | |
_displayText.postValue("I would really use a string resource!") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment