嗨,我是mvvm结构的新手,我在这里学习新的东西。目前,我已经绑定默认字符串与我的视图,我有多色文本,所以我选择使用HTML.fomHTml坚果,我无法使用谁可以帮助解决这个绑定问题下面我的测试代码.
data>
<import type="android.text.Html"/>
<variable
name="loginviewmodel"
type="app.road2xtech.neighbourhood.view.viewmodel.LoginViewModel" />
</data>
<TextView
android:id="@+id/textViewAccount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="56dp"
android:fontFamily="@font/raleway_regular"
android:gravity="center"
android:text="@={Html.fromHtml(loginviewmodel.accountString)}"
android:textColor="@android:color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />它会给我下面的错误
The expression 'android.text.Html.fromHtml(loginviewmodelAccountString)' cannot be inverted, so it cannot be used in a two-way binding
Details: There is no inverse for method fromHtml, you must add an @InverseMethod annotation to the method to indicate which method should be used when using it in two-way binding expressions发布于 2020-04-15 16:22:19
android:text="@={Html.fromHtml(loginviewmodel.accountString)}"InverseMethod注释可以应用于双向数据绑定中使用的任何方法。总而言之,在你的XMl中,如果你不需要双向绑定,那么最好使用这个。
android:text="@{Html.fromHtml(loginviewmodel.accountString)}"这将会起作用。:)
https://stackoverflow.com/questions/61223824
复制相似问题