Suppose I have this object:
public class Field
{
List<String> list;
public Field()
{
list = new ArrayList();
}
public boolean isOnTheList(String someText)
{
return list.contains(someText);
}
}
Now I want to use this function on a xml with binding like this.
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="android.view.View"/>
<variable
name="field"
type="com.greendao.db.Field"/>
<variable
name="user"
type="com.package.User"/>
</data>
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="@{field.isOnTheList(user.name)?View.VISIBLE:View.GONE}"
tools:context=".advisor.new_visit_report.activities.FieldsSelectionActivity"> ...
The problem is that is not working. Anyone has already tried this?
If everything else is set correctly, I would suggest to edit your method to return View.VISIBLE
or View.GONE
directly:
public int isOnTheList(String someText) {
return list.contains(someText) ? View.VISIBLE : View.GONE;
}
Used in xml:
android:visibility="@{field.isOnTheList(user.name)}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With