I followed the data binding documentation for Custom Binding Adapter for image loading from official Android Developers site: http://develo
Try this, work for me!. I hope this can help you. Simple way to change image resource without binding adapter.
and View Model Class :
public ObservableField imageButton;
private Context context;
//Constructor
public MainVM(Context context) {
this.context = context;
imageButton = new ObservableField<>();
setImageButton(R.mipmap.image_default); //set image default
}
public void onClickImageButton(View view) {
setImageButton(R.mipmap.image_change); //change image
}
private void setImageButton(@DrawableRes int resId){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
imageButton.set(context.getDrawable(resId));
}else{
imageButton.set(context.getResources().getDrawable(resId));
}
}