I'm trying to set the visibility
and the src
of an ImageView
using data binding. I don't know why this error is showing up, and I truely believe that this was working at one point, but I could be wrong.
Layout:
<data>
<import type="android.view.View" />
<import type="android.support.v4.content.ContextCompat" />
<variable
name="viewData"
type="com.myapp.SomethingViewData" />
</data>
...
<ImageView
...
android:src="@{ContextCompat.getDrawable(context, viewData.getIconResource())}"
android:visibility="@{viewData.getIconVisibility() ? View.VISIBLE : View.GONE}" />
Data class
@Parcelize
data class SomethingViewData(val iconResource: Int,
val iconVisibility: Boolean) : Parcelable
Error message:
error: '@{ContextCompat.getDrawable(context, viewData.getIconResource())}' is incompatible with attribute android:src (attr) reference|color.
error: '@{viewData.getIconVisibility() ? View.VISIBLE : View.GONE}' is incompatible with attribute android:visibility (attr) enum [gone=2, invisible=1, visible=0].
What does this mean and how do I fix it?
viewData.getIconVisibility()
is a boolean? – Seaware