Skip to content

Instantly share code, notes, and snippets.

@tobioyelekan
Last active May 24, 2020 14:53
Show Gist options
  • Save tobioyelekan/8d8ec95c5b0cabe96f66e1fc16414055 to your computer and use it in GitHub Desktop.
Save tobioyelekan/8d8ec95c5b0cabe96f66e1fc16414055 to your computer and use it in GitHub Desktop.
//ActivityViewModel.kt
private val _textToShow = MutableLiveData<String>()
val textToShow : LiveData<String>()
get() = textToShow
fun buttonClicked(){
_textToShow.value = "Hello"
}
//layout.xml
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="com.example.android.app.ui.viewmodels.ActivityViewModel"/>
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation:"vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/press_btn"
style="@style/normalButton"
android:id="@+id/button"
android:onClick="@{()->viewModel.buttonClicked()}"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{viewModel.textToShow}"/>
</LinearLayout>
</layout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment