Jan*_*ski 5 data-binding android swiperefreshlayout android-databinding androidx
我正在尝试使用 AndroidX 库实现滑动刷新功能:androidx.swiperrefreshlayout.widget.SwipeRefreshLayout
我的应用程序正在使用 Android 数据绑定,因此我想使用可观察字段来控制此小部件的状态。
过去我使用过AppCompat one - 它已被弃用。
以前,我可以通过以下方式访问字段:
<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>
Run Code Online (Sandbox Code Playgroud)
但是,这似乎不再适用 - 与 AndroidX 等效。我错过了什么吗?或者是否有任何解决方案/解决方法来实现这一目标?
我的项目已经完全迁移到AndroidX,没有错误或依赖冲突。
Mar*_*ler 12
那叫androidx.swiperefreshlayout.widget.SwipeRefreshLayout...
// https://mvnrepository.com/artifact/androidx.swiperefreshlayout/swiperefreshlayout
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
Run Code Online (Sandbox Code Playgroud)
例如:
<?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>
Run Code Online (Sandbox Code Playgroud)
然后onRefresh(),可以RecyclerView.Adapter从数据绑定中获取。
| 归档时间: |
|
| 查看次数: |
4903 次 |
| 最近记录: |