following is the layout file: I'm using custom setter i.e BindingAdapter
<ImageView
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="@dimen/_8dp"
android:layout_weight="4"
android:gravity="center"
android:padding="@dimen/_8dp"
bind:pic="@{item.deviceType}"
bind:status="@{item.deviceStatus}"
/>
the pic will get int value which biphergate the device the status is boolean value.
this is my bindingadpter:
@BindingAdapter(value = {"bind:status","bind:pic"},requireAll = false)
public static void setImage(ImageView imageview,boolean status,int type){
if(Integer.valueOf(type)==257){
if(status)
imageview.setImageResource(R.drawable.ic_lightbulb_on);
else
imageview.setImageResource(R.drawable.ic_lightbulb);
}else if(Integer.valueOf(type)==516){
if(status)
imageview.setImageResource(R.drawable.ic_open_door);
else
imageview.setImageResource(R.drawable.ic_closed_door);
}
}
now I am getting the response from retrofit after the execution of binding adapter, so how can I notify the binding that I've data and update the view and call binding adapter again?
after many hours I found out solutions you just need to add
notifyChange();
after you get the response from API.