androidandroid-databindingandroid-include

Databind Includes Layout


Trying to dynamically set the layout using databinding but I can't seem to get the ternary operator to work right. Must be missing escape character or something.

<include
    android:id="@+id/setting"
    bind:settingsViewModel="@{settingsViewModel}"
    layout="@{settingsViewModel.configFlag ? @layout/settings_v1 :@layout/settings_v2}" />

Seems simple enough but errors with "****/ data binding error ****msg:included value ... must start with @layout/. "


Solution

  • The answer to this is that you cannot do this. Layout is called before and so this logic cannot be done before hand.