带数据绑定的AndroidX SwiperFreshLayout

带数据绑定的AndroidX SwiperFreshLayout,android,data-binding,android-databinding,androidx,swiperefreshlayout,Android,Data Binding,Android Databinding,Androidx,Swiperefreshlayout,我正在尝试使用AndroidX库实现刷卡刷新功能:AndroidX.swiperefreshlayout.widget.swiperefreshlayout 我的应用程序使用Android数据绑定,因此我想使用可观察字段来控制此小部件的状态 在过去,我曾使用过——此后一直被弃用 以前,我可以通过以下方式访问字段: <android.support.v4.widget.SwipeRefreshLayout xmlns:app="http://schemas.android.com/a

我正在尝试使用AndroidX库实现刷卡刷新功能:AndroidX.swiperefreshlayout.widget.swiperefreshlayout

我的应用程序使用Android数据绑定,因此我想使用可观察字段来控制此小部件的状态

在过去,我曾使用过——此后一直被弃用

以前,我可以通过以下方式访问字段:

<android.support.v4.widget.SwipeRefreshLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:refreshing="@{viewModel.isLoading}">
    ...
    // My RecyclerView here
</android.support.v4.widget.SwipeRefreshLayout>

...
//我的回收站在这里
但是,这似乎不再起作用了——使用AndroidX等效物。 我错过什么了吗?或者是否有任何解决方案/解决方法来实现这一点


我的项目已经完全迁移到AndroidX,没有错误或冲突的依赖项。

您可以为此创建自己的BindingAdapter

这叫做

例如:

<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <data />

    <androidx.appcompat.widget.LinearLayoutCompat
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
            android:id="@+id/swipe_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:refreshing="@{viewModel.isLoading}"
            app:onRefreshListener="@{() -> viewModel.onRefresh()}">
            ...
        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

    </androidx.appcompat.widget.LinearLayoutCompat>

</layout>

...

然后,
onRefresh()
,就可以从数据绑定中获得
RecyclerView.Adapter

android x与swiperefreshlayout的等价物面临什么问题?@Kushal我无法访问app:swiperefreshlayout中的刷新。是的,我认为自定义绑定适配器可以解决这种情况。实际上,我想我以前在AppCompat中使用过一个。SwipeRefreshLayout正在公开setRefresh()方法,Android Studio没有在布局XML文件中正确地自动完成它,我错过了它。。。
<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <data />

    <androidx.appcompat.widget.LinearLayoutCompat
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
            android:id="@+id/swipe_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:refreshing="@{viewModel.isLoading}"
            app:onRefreshListener="@{() -> viewModel.onRefresh()}">
            ...
        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

    </androidx.appcompat.widget.LinearLayoutCompat>

</layout>