Android: data binding expression using enum transform

Is it possible to create an expression for data binding and control the visibility of a view element using enumerations? I want to achieve 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 great if I could use this enumeration in XML to control my visibility LinearLayout.

Has anyone understood how to achieve this?

+4
source share
2 answers

It seems to me that you want to achieve, and I do not see anything bad, except, perhaps, the lack of a tag? I do not see him ...

<data>
 <import type="com.example.my.app.EditType"/>
</data>
+10
source

. java- . , - @Demo_Mail , OnCreate() Activity/Fragment, , ( , ). OnClick() OnSelectItem(), , (, comboBox). .

0

Source: https://habr.com/ru/post/1677155/


All Articles