General data binding variable

How to determine the general type of data binding variable?

The following code never compiles.

<data>
    <variable
        name="viewModel"
        type="com.example.viewmodel.ViewModel<Model>"/>
</data>
+13
source share
4 answers

You need to exit & lt; Model> as below:

<data>
    <variable
        name="viewModel"
        type="com.example.viewmodel.ViewModel&lt;Model>"/>
</data>

Android Studio will still display a "Cannot resolve character" error, but the XML will compile. This is a known issue. From Android Studio support for data binding :

Note. Arrays and generic types, such as the Observable class, can display errors in the absence of errors.

+23
source

Try the following:

<data>
<variable
    name="viewModel"
    type="com.example.viewmodel.ViewModel&lt;Model&gt;"/>
</data>

&lt;responsible for < and &gt;responsible for.

+4

XML; XML .

<data>
    <variable
        name="viewModel"
        type="com.example.viewmodel.ViewModel&lt;Model>"/>
</data>
+1

- :

<data>
    <import type="com.example.path.Model"/>
    <variable
        name="obj"
        type="com.example.viewmodel.ViewModel&lt;Model&gt;"
        />
</data>

NOTE: you can write " > " or " &gt;" at the end of the "Model" should be in order

To avoid displaying errors, do not forget to add a line to say what type of object is used:

<import type="com.example.path.Model"/>
0
source

All Articles