Last active
September 14, 2017 01:03
-
-
Save n8ebel/dabcfe96d25363b6fc35e8d88e847498 to your computer and use it in GitHub Desktop.
Simple use of databinding to display a String and Int
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
<layout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools"> | |
<data> | |
<variable name="message" type="String" /> | |
<variable name="number" type="Integer" /> | |
</data> | |
<LinearLayout | |
android:orientation="vertical" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context="com.n8ebel.databindingsandbox.MainActivity" | |
> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:text="@{message}" | |
/> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:text='@{"And here we are binding a simple value like the number " + number}' | |
/> | |
</LinearLayout> | |
</layout> |
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
val binding = DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main).apply { | |
message = "hello" | |
number = 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment