即使我多次更新 LiveData,我的 BindingAdapter 也只运行一次。public class ButtonViewBindingAdapter{ @BindingAdapter("hideIfZero") public static void setHideIfZero(View view, MutableLiveData<Integer> currentPosition) { view.setVisibility(currentPosition.getValue() == 0 ? View.GONE : View.VISIBLE); }}<layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <data> <variable name="viewModel" type="com.package.PermissionsViewModel"/> <variable name="clickHandler" type="com.package.PermissionsActivity.ClickHandler"/> </data> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/buttonNext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentBottom="true" android:background="@null" android:onClick="@{() -> clickHandler.nextSlide()}" android:text="@string/intro_next" android:textColor="@android:color/white" /> <Button android:id="@+id/buttonBack" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentBottom="true" android:background="@null" android:onClick="@{() -> clickHandler.previousSlide()}" android:text="@string/intro_back" android:textColor="@android:color/white" app:hideIfZero="@{viewModel.currentSlidePosition}"/> </RelativeLayout></layout>当我更新视图模型中的值时,可见性仍然没有改变。BindingAdapter 不会多次运行。我在这里想念什么?我希望它在位置为 0 时隐藏,否则它应该显示。
添加回答
举报
0/150
提交
取消