Nguyen Hoà
Nguyen Hoà

Reputation: 353

Data binding generic variable and livedata

How to define Livedata genneric with type List ?

<import type="androidx.lifecycle.LiveData"/>

<import type="java.util.List"/>

<variable
        name="livedata"
        type="LiveData&lt;List>"/>

when compiling it throw error: incompatible types: Object cannot be converted to List but if i am using primitive type it work , how can i do this with List type?

Upvotes: 1

Views: 373

Answers (1)

Adrian Yama Yama
Adrian Yama Yama

Reputation: 96

You must infer the type of list, for example, if list is of type List of Integers you must do:

<import type="androidx.lifecycle.LiveData"/>

<import type="java.util.List"/>
<import type="Integer"/>

<variable
        name="livedata"
        type="LiveData&lt;List&lt;Integer&gt;&gt;"/>

Upvotes: 3

Related Questions