in my android app I have the following layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/news_tab"
android:clipToPadding="false">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listaNews1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:divider="@color/transparent"></ListView>
<LinearLayout
android:id="@+id/ll_news_empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/news_icon"
android:tint="@color/gray_dark"
android:scaleType="centerCrop" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nessuna news da mostrare"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/gray_dark"/>
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
And programmatically I have this code to add the empty view:
...
listaNovità = (ListView)view.findViewById(R.id.listaNews1);
listaNovità.setEmptyView(view.findViewById(R.id.ll_news_empty_view));
...
But executing the code on emulator I see an empty layout (the listview is empty and the empty view is not showing). What is the reason and how can I fix the problem?
Thanks everyone wants to help me.
Fragment
? If so, are you certain you're returning theView
you're doing that setup on?SwipeRefreshLayout
; rather, due to having both things as direct children of it. I'll have to look into that, but if you wrap theListView
and theLinearLayout
in aFrameLayout
, it should work.getChildAt(0)
. Any other children are ignored, so they're basically invisible.