gpt4 book ai didi

android - android数据绑定(bind)代码中的 "@get:Bindable"是什么?

转载 作者:行者123 更新时间:2023-12-04 02:53:51 28 4
gpt4 key购买 nike

我是 android 数据绑定(bind)的新手,我正在查看代码,如下所示

 @get:Bindable
var userIds: MutableList<Long> = mutableListOf()
private set(value) {
field = value
notifyPropertyChanged(BR.userIds)
}

那么,@get:Bindable 在这里做了什么。 @Bindable@get:Bindable 一样吗?

最佳答案

@get:可绑定(bind)

In simple words, this will put @Bindable annotation on getter of userIds.

以下两个是相同的。或者你可以说两种在 getter 上添加注解的方法。

@get:Bindable
var userIds: MutableList<Long> = mutableListOf()
private set(value) {
field = value
notifyPropertyChanged(BR.userIds)
}

var userIds: MutableList<Long> = mutableListOf()
@Bindable get() = _title
set(value) {
field = value
notifyPropertyChanged(BR.userIds)
}

为了在Java中更清楚地理解,与下面相同。

private ArrayList<Long> userIds = new ArrayList<>();

@Bindable
public ArrayList<Long> getUserIds() {
return userIds;
}

public void setUserIds(ArrayList<Long> userIds) {
this.userIds = userIds;
notifyPropertyChanged(BR.selected);
}

您可以在 official doc 上了解更多关于 Annotations 的信息.

关于android - android数据绑定(bind)代码中的 "@get:Bindable"是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53910028/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com