Skip to content

Instantly share code, notes, and snippets.

@n8ebel
Last active September 14, 2017 01:03
Show Gist options
  • Save n8ebel/dabcfe96d25363b6fc35e8d88e847498 to your computer and use it in GitHub Desktop.
Save n8ebel/dabcfe96d25363b6fc35e8d88e847498 to your computer and use it in GitHub Desktop.
Simple use of databinding to display a String and Int
<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>
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