Last active
May 24, 2020 14:53
-
-
Save tobioyelekan/8d8ec95c5b0cabe96f66e1fc16414055 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
//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