如何使用Android数据绑定设置SwipeRefreshLayout刷新属性? [英] How to set SwipeRefreshLayout refreshing property using android data binding?

查看:112
本文介绍了如何使用Android数据绑定设置SwipeRefreshLayout刷新属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用android数据绑定库. 如果要使视图可见,可以编写如下内容:

I am using android data binding library. If I want to make a view visible I can write something like this:

<TextView
            android:id="@+id/label_status"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="@{habitListViewModel.message}"
            app:visibility="@{habitListViewModel.hasError ? View.VISIBLE : View.GONE}" />

是否存在以类似(xml)方式绑定到swipeRefreshLayout的refresh属性的选项?

Is there an option to bind to a refresh property of swipeRefreshLayout in a similar (xml) way?

当前,我通过调用setRefreshing(true/false)在代码中进行设置,但希望在xml中使其一致.

Currently I am setting it in code by calling setRefreshing(true/false) but would love to make it in xml to be consistent.

推荐答案

更新: 当数据绑定从xml属性名称映射到set{AttributeName}时,您可以只使用app:refreshing,因为数据绑定将成功地将值提供给SwipeRefreshLayoutsetRefreshing方法(幸运的是我们存在并且是公开的):

UPDATED: As databinding maps from xml attribute name to set{AttributeName}, you can just use app:refreshing, as databinding will successfully supply the value to setRefreshing method of SwipeRefreshLayout (which luckily for us exists and is public):

<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="@{habitListViewModel.isLoading}">
    ...
    //ListView,RecyclerView or something
</android.support.v4.widget.SwipeRefreshLayout>

就是这样!请注意,您可以简单地使用@{true}@{false}而不是@{habitListViewModel.isLoading}.希望有帮助.

That's it! Note, that you can simply use @{true} or @{false} instead of @{habitListViewModel.isLoading}. Hope that helps.

这篇关于如何使用Android数据绑定设置SwipeRefreshLayout刷新属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆