Issue
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<import type="android.view.View" />
<variable
name="notificationResponse"
type="myms.models.NotificationResponse"/>
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
...........
<TextView
android:id="@+id/tv_empty_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_12dp"
android:layout_marginRight="@dimen/_12dp"
android:minHeight="@dimen/_60dp"
android:gravity="center"
android:textSize="@dimen/_18sp"
android:textStyle="bold"
android:text="No Message"
android:background="@color/white"
android:visibility="@{notificationResponse.payloads.size() > 0 ? View.GONE : View.VISIBLE}"/>
......
</FrameLayout>
</layout>
What i want to achieve is that by default the view should be GONE and after the async call in my code where i actually bind the notificationResponse object it should decide whether to show or hide the view.
Solution
The Interpretation of the code you have written android:visibility="@{notificationResponse.payloads.size() > 0 ? View.GONE : View.VISIBLE}"
is
When your list size is having more than one data you want to hide that TextView
and in other case you want to show it.
Not when you are calling your API, your list size will definitely less than or equal 0 so it will not be visible.
Solution :
Pass some variable which indicates API is still calling in background and when API call is done, set that variable to false.
android:visibility="@{notificationResponse.payloads.size() > 0 || !loading ? View.GONE : View.VISIBLE}"
It means if your list size is more than one and API call is done, TextView
should hide.
By default value of loading should be false, when you calling API change that value to true and when API call is done again set it to false.
Answered By - Ravi
Answer Checked By - Timothy Miller (JavaFixing Admin)