android数据绑定_Android RecyclerView数据绑定

android数据绑定

In this tutorial, we’ll be discussing and implementing the RecyclerView Using Data Binding in our Android Application.

在本教程中,我们将在Android应用程序中讨论和实现RecyclerView using Data Binding。

Android RecyclerView数据绑定 (Android RecyclerView DataBinding)

In order to know the basics of Android DataBinding, do visit this tutorial.

为了了解Android DataBinding的基础知识,请访问本教程

Data Binding significantly reduces the boilerplate code. Here, we’ll learn how to implement DataBinding with a RecyclerView which has the ViewHolder pattern.

数据绑定大大减少了样板代码。 在这里,我们将学习如何使用具有ViewHolder模式的RecyclerView来实现DataBinding。

Also, we’ll understand how Data Binding makes it easy to generalise the Adapter classes.

此外,我们还将了解数据绑定如何使通用化Adapter类变得容易。

Finally, we’ll demonstrate how to directly pass the adapter object in the XML.

最后,我们将演示如何在XML中直接传递适配器对象。

入门 (Getting Started)

Add the following code in your app’s build.gradle:

在您应用的build.gradle添加以下代码:

android{
...
dataBinding {
        enabled = true
    }
...
}

Add the following dependency.

添加以下依赖项。

implementation 'com.android.support:design:28.0.0'

项目结构 (Project Structure)

In the below application we’ll load the data in the adapter rows of the RecyclerView from the XML using the <data>. Also we’ll set the onClickListener methods in the layout rows itself.

在下面的应用程序中,我们将使用<data>从XML将数据加载到RecyclerView的适配器行中。 另外,我们将在布局行本身中设置onClickListener方法。

(

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值