Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "@get:Bindable" in the android data binding code?

Tags:

android

I am new to the android data binding and I was looking at the code which says, as bellow

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

so, what is the @get:Bindable does here. Is the @Bindable and @get:Bindable same?

like image 995
Lalit Behera Avatar asked Jun 29 '26 19:06

Lalit Behera


1 Answers

@get:Bindable

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

Below two are identical to each other. Or you can say two ways to put annotation on 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)
    }

For understanding more clearly in Java, it is identical to below.

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);
}

You can understand more about Annotations on official doc.

like image 139
Khemraj Sharma Avatar answered Jul 09 '26 04:07

Khemraj Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!