Android data binding on drawable -
i hv 2 shape drawables, rounded_corners.xml , rounded_corners_red.xml used show valid text input , invalid text input respectivly.
i want drwable set dynamically when user click on login button such if valid text show rounded_corners.xml , if invalid show rounded_corners_red.xml.
below how hv put in layout xml.
<edittext android:id="@+id/et_ip" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@={systemsettings.isvalid ? @drawable/rounded_corners : @drawable/rounded_corners_red}" android:text="@={systemsettings.serverip, default=@string/ip_host}" android:textcolor="#000000" />
i want drawable applied dynamically based on isvalid observable varible defined in model class. code compiles no errors. gives run time error
java.lang.runtimeexception: found data binding errors. ****/ data binding error ****msg:the expression ((systemsettingsisvalidget) ? (getdrawablefromresource(etip, r.drawable.rounded_corners)) : (getdrawablefromresource(etip, r.drawable.rounded_corners_red))) cannot cannot inverted: condition of ternary operator must constant: android.databinding.tool.writer.kcode@429a75fd file:d:xxx\app\src\main\res\layout\fragment_system_settings.xml loc:92:47 - 92:128 ****\ data binding error ****
anyone knows why happens? thanks.
your statement 2-way binding @={}
@={systemsettings.isvalid ? @drawable/rounded_corners : @drawable/rounded_corners_red}`
that's why find error stating expression
cannot cannot inverted
it gives reason direcly:
the condition of ternary operator must constant
but since you're getting drawable resources it's save remove =
expression.
Comments
Post a Comment