is it possible to create a databinding expression and control the visibility of a view element by using enumerations? What I want to achieve is the following
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="@{user.editType == EditType.EDIT_PROFIL ? View.VISIBLE : View.GONE}">
The EditType class is very simple
public enum EditType {
NONE,
EDIT_PROFIL,
EDIT_ADDRESSES; }
It would be awesome if I can use this enumeration within the XML to control the visibility of my LinearLayout
.
Anybody got an idea how to achieve this?
The main advantages of viewbinding are speed and efficiency. It has a shorter build time because it avoids the overhead and performance issues associated with DataBinding due to annotation processors affecting DataBinding's build time.
Data Binding allows you to effortlessly communicate across views and data sources. This pattern is important for many Android designs, including model view ViewModel (MVVM), which is currently one of the most common Android architecture patterns.
Stay organized with collections Save and categorize content based on your preferences. The @={} notation, which importantly includes the "=" sign, receives data changes to the property and listen to user updates at the same time.
Layout Binding expressions Expressions in the XML layout files are assigned to a value of the attribute properties using the “ @{} " syntax. We just need to use the basic syntax @{} in an assignment expression.
To me it seems like what you want to achieve is possible and I dont see anything wrong except maybe u lack of the tag? I dont see it...
<data> <import type="com.example.my.app.EditType"/> </data>
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