I am trying to set the visibility of a Textview
depending on the response returned by Retrofit . onFailure
, I am setting the visibility to visible tv_no_cat.setVisibility(View.VISIBLE);
However, this does not work. I am doing the same with a ContentLoadingProgressBar
and it's working appropriately. Here is my code
public void onFailure(Call<List<MoviesCategory>> call, Throwable t) {
tv_no_cat.setVisibility(View.VISIBLE); ////This does not work
Boolean x = tv_no_cat.getVisibility() == View.VISIBLE;
Toast.makeText(getContext(), "Network Error "+x, Toast.LENGTH_LONG).show(); //This shows true
tv_no_cat.setTextColor(Color.BLUE);
videoLoadingPb.setVisibility(View.GONE); //This works
}
My guess is that am trying to set the textview
which is on UI thread from another thread. If so, why is it working for the ContentLoadingProgressBar
?
Here is my xml for the 2 views
<android.support.v4.widget.ContentLoadingProgressBar
android:id="@+id/loading_categories"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:visibility="visible" />
<TextView
android:layout_below="@id/loading_categories"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No Movie Category Found"
android:id="@+id/tv_no_cat"
android:textAlignment="center"
android:layout_gravity="bottom"
android:visibility="gone"
/>
Any help on how I can set the textview
Visibility to VISIBLE
is welcome.