Is it possible to use data-binding for a SeekBar or ProgressBar in Android? I have this data element:
Well you may need to use two-way binding like below.
Add in binding utils class
private static final String ANDROID_PROGRESS = "android:progress";
@BindingAdapter(ANDROID_PROGRESS)
public static void setSeekbarProgress(SeekBar seekBar, int progress) {
try {
seekBar.setProgress(progress);
} catch (Resources.NotFoundException nfe) {
nfe.printStackTrace();
}
}
@InverseBindingAdapter(attribute = ANDROID_PROGRESS)
public static int getSeekbarProgress(SeekBar seekBar) {
try {
return seekBar.getProgress();
} catch (Resources.NotFoundException nfe) {
nfe.printStackTrace();
return 0;
}
}
Add the observable in view model
var child1Age = ObservableField(1)
In the layout