I see this error while updating a textview once the image has been successfully rendered by Glide.
Fatal Exception: java.lang.IllegalStateException: Required DataBindingComponent is null in class CustomBinding. A BindingAdapter in CustomViewModel is not static and requires an object to use, retrieved from the DataBindingComponent. If you don't use an inflation method taking a DataBindingComponent, use DataBindingUtil.setDefaultComponent or make all BindingAdapter methods static.
@BindingAdapter(value = { "android:src", "placeHolder" }, requireAll = false)
public void setUrl(ImageView imageView, String url, Drawable placeHolder) {
Glide.with(imageView.getContext())
.load(url)
.placeholder(placeHolder)
.centerCrop()
.listener(new Listener<String, Drawable>() {
@Override
public boolean onException() {
viewmodel.setTextVisible(true);// ERROR!
return false;
}
@Override public boolean onResourceReady() {
viewmodel.setTextVisible(false); // ERROR!
return false;
}
})
.into(imageView);
}
public void setTextVisible(boolean visibility) {
textVisibility = visibility;
notifyPropertyChanged(BR.textVisibility);
}
@Bindable
public boolean getTextVisible() {
return textVisibility;
}
This is how i initialise the viewmodel and bind the data inside the fragment:
CustomBinding binding =
DataBindingUtil.inflate(inflater, R.layout.custom, container,
false);
CustomViewModel viewModel = new CustomViewModel(data, context);
binding.setHandlers(new CustomHandlers(context));
binding.setData(viewModel);
I cant find a way to actually implement this within a viewmodel. Thanks in advance for the help.