I am unable to update ProgressBar progress with data binding.
Here's what I am doing -
- I have a model for holding ProgressBar current progress.
ModelProgress.java
public class ModelProgress extends BaseObservable {
private int total;
private int current;
public void setCurrent(int current) {
this.current = current;
notifyPropertyChanged(BR.progress);
}
@Bindable
public int getProgress() {
return (current / total) * 100;
}
}
Please Note I have made getProgress() @Bindable and notifying BR.progress on updation of value current. So that UI attached to BR.progress update when change in variable current.
In XML I tried to attach ProgressBar with variable progress.
<ProgressBar
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:progress="@{model.progress}"
tools:progress="50" />
Problem
It's all set for me. Now when I call setCurrent() method, it should reflect on UI. Like binding.getModel().setCurrent(50);. But it doesn't.