I am trying to get drawables depending on if a function is false or true. But i am doing something wrong. So any help is appreciated
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:onClick="@{() -> handler.onVoteClicked(gameFeed.uid)}"
android:src="@{() -> handler.existInList(feed.ratings,feed.uid) ? @drawable/ic_star_border : @drawable/ic_star}"
android:layout_gravity="center_vertical"/>
This is the function i am trying to call from my handler.
public boolean existInList(Map<String,Boolean> ratings, String userId) {
for (Map.Entry<String, Boolean> entry : ratings.entrySet()) {
if(entry.getValue().equals(userId)) {
return true;
}
}
return false;
}
Added error that i got
Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.RuntimeException: Found data binding errors.
****/ data binding error ****msg:Cannot find the proper callback class
for android:src. Tried android.graphics.drawable.Drawable but it has 4 abstract methods, should have 1 abstract methods. file:/Users/brahim/ProjectNinjo/app/src/main/res/layout/adapter_feed_row.xml loc:108:33 - 108:135 ****\ data binding error ****
Update
What i noticed is that it can grab the drawable. But it has problems calling that function. Im guessing that i cant call a function from a ternary operator or i am calling the function in a bad way