I am using Android data binding which works great:
<TextView
android:text="@{ee.Name}"
...
But if I do that the Android Studio designer doesn't show any text. Without text I can't see the TextView at all. Which is understandable because I haven't bound the data yet. Is there something like a fallback value or a default value which can be displayed until there is real data?
You should read the Data Binding Guide posted on the Android developers website. The last section of the document, Android Studio Support for Data Binding explain how you can use a placeholder that can help you during the design phase. It's very simple:
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{user.firstName, default=Placeholder}"/>
If you want to have text with spaces as placeholder you can use single quotes ('), back quotes (`) or "
android:text='@{user.firstName, default="Placeholder text"}'
android:text="@{user.firstName, default=`Placeholder text`}"
android:text="@{user.firstName, default="Placeholder text"}"
android:text="@{user.firstName, default=@string/placeholder_text}"
The Preview pane displays default values for data binding expressions.
android:text="@{user.firstName, default=PLACEHOLDER}"
This can set default value .
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@{defaultString ?? @string/hello_world}"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With