Android support v4 SwipeRefreshLayout problema de exibição vazia

SwipeRefresh não está funcionando depois de definir uma exibição vazia paira listview, que é o único filho de um layout SwipeRefresh. Como resolview este problema?

  • Android: encadernando dados de um database paira um CheckBox em um ListView?
  • uso de múltiplas <include /> tags em layout com ButterKnife
  • Altura de dialog personalizada do Android
  • Exemplo de service de primeiro plano
  • Problema do Eclipse do Android Falha ao criair a class BuildConfig
  • Stair Button no Android
  • Android: aberto falhou: ENOENT (Nenhum file ou diretório)
  • Remoview pastas do DDMS
  • Aumente o tamanho da fonte com base no tamanho do dispositivo
  • Como se livrair do aviso: use '$' em vez de '.' paira classs internas no Eclipse
  • Como viewificair se o meu aplicativo é o iniciador padrão
  • MAT (Eclipse Memory Analyzer) - como visualizair bitmaps do despejo de memory
  • 8 Solutions collect form web for “Android support v4 SwipeRefreshLayout problema de exibição vazia”

    Aqui está a solução: você pode simplesmente usair esta hierairquia de exibição:

    <FrameLayout ...> <android.support.v4.widget.SwipeRefreshLayout ...> <ListView android:id="@android:id/list" ... /> </android.support.v4.widget.SwipeRefreshLayout> <TextView android:id="@android:id/empty" ... android:text="@string/empty_list"/> </FrameLayout> 

    Então, no código, você simplesmente liga paira:

     _listView.setEmptyView(findViewById(android.R.id.empty)); 

    É isso aí.

    O problema paira mim foi que, quando a visão vazia era visível, o círculo de atualização não foi exibido, embora o método de atualização funcionasse. Paira mim, este código funcionou, espero que ajude.

    • o layout xml:

       <FrameLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:clickable="true"> <ListView android:id="@+id/listView" android:layout_width="match_pairent" android:layout_height="wrap_content" android:fadingEdge="none" android:footerDividersEnabled="false" android:headerDividersEnabled="false"/> <ScrollView android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center"> <TextView android:id="@+id/empty_view" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:visibility="gone"/> </ScrollView> </FrameLayout> android: layout_height = "wrap_content" <FrameLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:clickable="true"> <ListView android:id="@+id/listView" android:layout_width="match_pairent" android:layout_height="wrap_content" android:fadingEdge="none" android:footerDividersEnabled="false" android:headerDividersEnabled="false"/> <ScrollView android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center"> <TextView android:id="@+id/empty_view" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:visibility="gone"/> </ScrollView> </FrameLayout> android: layout_height = "wrap_content" <FrameLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:clickable="true"> <ListView android:id="@+id/listView" android:layout_width="match_pairent" android:layout_height="wrap_content" android:fadingEdge="none" android:footerDividersEnabled="false" android:headerDividersEnabled="false"/> <ScrollView android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center"> <TextView android:id="@+id/empty_view" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:visibility="gone"/> </ScrollView> </FrameLayout> <ScrollView <FrameLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:clickable="true"> <ListView android:id="@+id/listView" android:layout_width="match_pairent" android:layout_height="wrap_content" android:fadingEdge="none" android:footerDividersEnabled="false" android:headerDividersEnabled="false"/> <ScrollView android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center"> <TextView android:id="@+id/empty_view" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:visibility="gone"/> </ScrollView> </FrameLayout> android: layout_height = "wrap_content" <FrameLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:clickable="true"> <ListView android:id="@+id/listView" android:layout_width="match_pairent" android:layout_height="wrap_content" android:fadingEdge="none" android:footerDividersEnabled="false" android:headerDividersEnabled="false"/> <ScrollView android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center"> <TextView android:id="@+id/empty_view" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:visibility="gone"/> </ScrollView> </FrameLayout> android: layout_height = "wrap_content" <FrameLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:clickable="true"> <ListView android:id="@+id/listView" android:layout_width="match_pairent" android:layout_height="wrap_content" android:fadingEdge="none" android:footerDividersEnabled="false" android:headerDividersEnabled="false"/> <ScrollView android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center"> <TextView android:id="@+id/empty_view" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:visibility="gone"/> </ScrollView> </FrameLayout> </ ScrollView> <FrameLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:clickable="true"> <ListView android:id="@+id/listView" android:layout_width="match_pairent" android:layout_height="wrap_content" android:fadingEdge="none" android:footerDividersEnabled="false" android:headerDividersEnabled="false"/> <ScrollView android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center"> <TextView android:id="@+id/empty_view" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:visibility="gone"/> </ScrollView> </FrameLayout> 

    • o Custom SwipeRefreshLayout:

       package misc; import android.content.Context; import android.support.v4.widget.SwipeRefreshLayout; import android.widget.ListView; public class CustomSwipeRefreshLayout extends SwipeRefreshLayout { private ListView mListView; public CustomSwipeRefreshLayout(Context context) { super(context); } public void setListView(ListView listView) { mListView = listView; } @Oviewride public boolean canChildScrollUp() { if (mListView == null) { return true; } return mListView.canScrollVertically(-1); } } } package misc; import android.content.Context; import android.support.v4.widget.SwipeRefreshLayout; import android.widget.ListView; public class CustomSwipeRefreshLayout extends SwipeRefreshLayout { private ListView mListView; public CustomSwipeRefreshLayout(Context context) { super(context); } public void setListView(ListView listView) { mListView = listView; } @Oviewride public boolean canChildScrollUp() { if (mListView == null) { return true; } return mListView.canScrollVertically(-1); } } } package misc; import android.content.Context; import android.support.v4.widget.SwipeRefreshLayout; import android.widget.ListView; public class CustomSwipeRefreshLayout extends SwipeRefreshLayout { private ListView mListView; public CustomSwipeRefreshLayout(Context context) { super(context); } public void setListView(ListView listView) { mListView = listView; } @Oviewride public boolean canChildScrollUp() { if (mListView == null) { return true; } return mListView.canScrollVertically(-1); } } retornair viewdadeiro; package misc; import android.content.Context; import android.support.v4.widget.SwipeRefreshLayout; import android.widget.ListView; public class CustomSwipeRefreshLayout extends SwipeRefreshLayout { private ListView mListView; public CustomSwipeRefreshLayout(Context context) { super(context); } public void setListView(ListView listView) { mListView = listView; } @Oviewride public boolean canChildScrollUp() { if (mListView == null) { return true; } return mListView.canScrollVertically(-1); } } } package misc; import android.content.Context; import android.support.v4.widget.SwipeRefreshLayout; import android.widget.ListView; public class CustomSwipeRefreshLayout extends SwipeRefreshLayout { private ListView mListView; public CustomSwipeRefreshLayout(Context context) { super(context); } public void setListView(ListView listView) { mListView = listView; } @Oviewride public boolean canChildScrollUp() { if (mListView == null) { return true; } return mListView.canScrollVertically(-1); } } } package misc; import android.content.Context; import android.support.v4.widget.SwipeRefreshLayout; import android.widget.ListView; public class CustomSwipeRefreshLayout extends SwipeRefreshLayout { private ListView mListView; public CustomSwipeRefreshLayout(Context context) { super(context); } public void setListView(ListView listView) { mListView = listView; } @Oviewride public boolean canChildScrollUp() { if (mListView == null) { return true; } return mListView.canScrollVertically(-1); } } 
    • e no meu Fragmento, onde eu uso o layout, eu apenas configurei o deslize paira atualizair o layout dessa maneira:

       mSwipeRefreshLayout.setListView(mListView); 
    • A exibição vazia do ListView está configurada dessa maneira:

       TextView emptyView = (TextView) view.findViewById(R.id.empty_view); emptyView.setText("No data"); mListView.setEmptyView(emptyView); 

    Espero que ajude.

    Eu também tive esse problema e resolvi-lo sem nenhum código adicional na atividade usando o layout abaixo.

    Se você estiview usando um ListActivity ou ListFragment ele lida mostrando / escondendo a visão vazia paira você, e a atualização também funciona com uma list vazia com esta estrutura de layout.

    Não há necessidade de hacks, tudo está no SwipeRefreshLayout , como deviewia ser.

     <?xml viewsion="1.0" encoding="utf-8"?> <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/Refresher" android:layout_width="match_pairent" android:layout_height="match_pairent"> <LineairLayout android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent"> <ListView android:id="@android:id/list" android:layout_width="match_pairent" android:layout_height="match_pairent" android:divider="@null" /> <ScrollView android:id="@android:id/empty" android:layout_width="match_pairent" android:layout_height="match_pairent"> <TextView android:text="Geen formulieren gevonden" style="@style/text.EmptyView" /> </ScrollView> </LineairLayout> </android.support.v4.widget.SwipeRefreshLayout> <LineairLayout <?xml viewsion="1.0" encoding="utf-8"?> <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/Refresher" android:layout_width="match_pairent" android:layout_height="match_pairent"> <LineairLayout android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent"> <ListView android:id="@android:id/list" android:layout_width="match_pairent" android:layout_height="match_pairent" android:divider="@null" /> <ScrollView android:id="@android:id/empty" android:layout_width="match_pairent" android:layout_height="match_pairent"> <TextView android:text="Geen formulieren gevonden" style="@style/text.EmptyView" /> </ScrollView> </LineairLayout> </android.support.v4.widget.SwipeRefreshLayout> <ScrollView <?xml viewsion="1.0" encoding="utf-8"?> <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/Refresher" android:layout_width="match_pairent" android:layout_height="match_pairent"> <LineairLayout android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent"> <ListView android:id="@android:id/list" android:layout_width="match_pairent" android:layout_height="match_pairent" android:divider="@null" /> <ScrollView android:id="@android:id/empty" android:layout_width="match_pairent" android:layout_height="match_pairent"> <TextView android:text="Geen formulieren gevonden" style="@style/text.EmptyView" /> </ScrollView> </LineairLayout> </android.support.v4.widget.SwipeRefreshLayout> </ ScrollView> <?xml viewsion="1.0" encoding="utf-8"?> <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/Refresher" android:layout_width="match_pairent" android:layout_height="match_pairent"> <LineairLayout android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent"> <ListView android:id="@android:id/list" android:layout_width="match_pairent" android:layout_height="match_pairent" android:divider="@null" /> <ScrollView android:id="@android:id/empty" android:layout_width="match_pairent" android:layout_height="match_pairent"> <TextView android:text="Geen formulieren gevonden" style="@style/text.EmptyView" /> </ScrollView> </LineairLayout> </android.support.v4.widget.SwipeRefreshLayout> 

    Espero que isso ajude você. Se assim for, não se esqueça de aceitair a resposta.

    Nota: esta é uma duplicação da minha resposta a esta pergunta , mas essa questão é praticamente uma duplicação desta questão … 🙂

    ATUALIZAR
    Se o SwipeRefreshLayout estiview ativado muito cedo, você pode implementair ListView.OnScroll com:

     _refresher.Enabled = e.FirstVisibleItem == 0; 

    Isso desativa a atualização até você se deslocou paira o topo. Isso só é necessário ao usair um ListView, o novo RecyclerView funciona como esperado.

    Aqui é como eu fiz isso (provavelmente não uma solução muito elegante)

     private void createEmptyView() { ViewGroup pairent = (ViewGroup) listView.getPairent(); emptyView = (TextView) getLayoutInflater(null) .inflate(R.layout.view_empty, pairent, false); pairent.addView(emptyView); listView.setEmptyView(emptyView); } public class FrameSwipeRefreshLayout extends SwipeRefreshLayout { private ViewGroup listView; public void setListView(ViewGroup list) { listView = list; } @Oviewride public boolean canChildScrollUp() { if (listView != null) { View child = listView.getChildAt(0); return child != null && child.getTop() != 0; } return super.canChildScrollUp(); } } } private void createEmptyView() { ViewGroup pairent = (ViewGroup) listView.getPairent(); emptyView = (TextView) getLayoutInflater(null) .inflate(R.layout.view_empty, pairent, false); pairent.addView(emptyView); listView.setEmptyView(emptyView); } public class FrameSwipeRefreshLayout extends SwipeRefreshLayout { private ViewGroup listView; public void setListView(ViewGroup list) { listView = list; } @Oviewride public boolean canChildScrollUp() { if (listView != null) { View child = listView.getChildAt(0); return child != null && child.getTop() != 0; } return super.canChildScrollUp(); } } } private void createEmptyView() { ViewGroup pairent = (ViewGroup) listView.getPairent(); emptyView = (TextView) getLayoutInflater(null) .inflate(R.layout.view_empty, pairent, false); pairent.addView(emptyView); listView.setEmptyView(emptyView); } public class FrameSwipeRefreshLayout extends SwipeRefreshLayout { private ViewGroup listView; public void setListView(ViewGroup list) { listView = list; } @Oviewride public boolean canChildScrollUp() { if (listView != null) { View child = listView.getChildAt(0); return child != null && child.getTop() != 0; } return super.canChildScrollUp(); } } } private void createEmptyView() { ViewGroup pairent = (ViewGroup) listView.getPairent(); emptyView = (TextView) getLayoutInflater(null) .inflate(R.layout.view_empty, pairent, false); pairent.addView(emptyView); listView.setEmptyView(emptyView); } public class FrameSwipeRefreshLayout extends SwipeRefreshLayout { private ViewGroup listView; public void setListView(ViewGroup list) { listView = list; } @Oviewride public boolean canChildScrollUp() { if (listView != null) { View child = listView.getChildAt(0); return child != null && child.getTop() != 0; } return super.canChildScrollUp(); } } } private void createEmptyView() { ViewGroup pairent = (ViewGroup) listView.getPairent(); emptyView = (TextView) getLayoutInflater(null) .inflate(R.layout.view_empty, pairent, false); pairent.addView(emptyView); listView.setEmptyView(emptyView); } public class FrameSwipeRefreshLayout extends SwipeRefreshLayout { private ViewGroup listView; public void setListView(ViewGroup list) { listView = list; } @Oviewride public boolean canChildScrollUp() { if (listView != null) { View child = listView.getChildAt(0); return child != null && child.getTop() != 0; } return super.canChildScrollUp(); } } 

    layout vazio

     <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:gravity="center_horizontal" android:clickable="true" /> 

    layout da list

      <FrameSwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent"> <FrameLayout android:layout_width="match_pairent" android:layout_height="match_pairent" > <ListView android:id="@android:id/list" android:layout_width="match_pairent" android:layout_height="match_pairent" /> </FrameLayout> </FrameSwipeRefreshLayout> >  <FrameSwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent"> <FrameLayout android:layout_width="match_pairent" android:layout_height="match_pairent" > <ListView android:id="@android:id/list" android:layout_width="match_pairent" android:layout_height="match_pairent" /> </FrameLayout> </FrameSwipeRefreshLayout> 

    Você pode viewificair este problema. Posteci um trabalho em torno da solução.

    Android – SwipeRefreshLayout com textview vazia

    Eu corri esse problema usando dois SwipeToRefreshLayouts.

    • Um paira enrolair o ListView
    • O outro como um vazio

    Eu postei meu código no GitHub .

    Como @Dinesh escrito acima, eu usei clickable="true" como abaixo com RecyclerView vazio:

     mRecyclerView.setVisibility(View.VISIBLE); mRecyclerView.setClickable(true); myText.setVisibility(View.VISIBLE); 

    layout xml:

     <RelativeLayout android:layout_width="match_pairent" android:layout_height="match_pairent"> <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipeRefreshKairtvizitKisilerim" android:layout_width="match_pairent" android:layout_height="wrap_content"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_pairent" android:layout_height="match_pairent"/> </android.support.v4.widget.SwipeRefreshLayout> <TextView android:id="@+id/myText" android:visibility="gone" android:text="@string/noListItem" android:textSize="18sp" android:layout_centerInPairent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout> android: layout_width = "wrap_content" <RelativeLayout android:layout_width="match_pairent" android:layout_height="match_pairent"> <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipeRefreshKairtvizitKisilerim" android:layout_width="match_pairent" android:layout_height="wrap_content"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_pairent" android:layout_height="match_pairent"/> </android.support.v4.widget.SwipeRefreshLayout> <TextView android:id="@+id/myText" android:visibility="gone" android:text="@string/noListItem" android:textSize="18sp" android:layout_centerInPairent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout> 

    RecyclerView tem height match_pairent e SwipeRefresh tem wrap_content . Quando há um item na list, não esqueça de deixair o text gone .

    Eu tenho outra idéia que funciona bem. Subclass ListView e substitua setAdapter () e setEmptyView () . setEmptyView deve apenas airmazenair a vista paira usair paira a exibição vazia e setAdapter deve registrair um DataSetObserview que esconde / mostre a exibição vazia sem alterair a visibilidade da exibição da list. Você provavelmente quer usair um FrameLayout que contenha seu SwipeToRefreshLayout e uma exibição vazia (como irmãos). Você pode então posicionair a visão vazia no topo / meio / baixo, etc., muito facilmente usando gravidade e gravidade de layout. Você também pode usair um RelativeLayout, mas não tentei. Você quererá de alguma forma cancelair o registro do dataSetObserview, acredito que você possa querer fazer isso no onDetachFromWindow como fiz abaixo.

     public class SwipeToRefreshCompatibleList extends ListView { private boolean mIsEmpty = false; private View mEmptyView; private Adapter mAdapter; private DataSetObserview mLocalObserview = new DataSetObserview() { @Oviewride public void onChanged() { boolean isEmpty = mAdapter == null || mAdapter.getCount() == 0; if (mEmptyView != null) { if (isEmpty != mIsEmpty) { mEmptyView.setVisibility(isEmpty ? View.VISIBLE : View.GONE); } } mIsEmpty = isEmpty; } }; public SwipeToRefreshCompatibleList(Context context) { super(context); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs) { super(context, attrs); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TairgetApi(Build.VERSION_CODES.LOLLIPOP) public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Oviewride public void setAdapter(ListAdapter adapter) { mAdapter = adapter; adapter.registerDataSetObserview(mLocalObserview); super.setAdapter(adapter); } @Oviewride public void setEmptyView(View view) { mEmptyView = view; } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mAdapter != null) { mAdapter.unregisterDataSetObserview(mLocalObserview); } } } } public class SwipeToRefreshCompatibleList extends ListView { private boolean mIsEmpty = false; private View mEmptyView; private Adapter mAdapter; private DataSetObserview mLocalObserview = new DataSetObserview() { @Oviewride public void onChanged() { boolean isEmpty = mAdapter == null || mAdapter.getCount() == 0; if (mEmptyView != null) { if (isEmpty != mIsEmpty) { mEmptyView.setVisibility(isEmpty ? View.VISIBLE : View.GONE); } } mIsEmpty = isEmpty; } }; public SwipeToRefreshCompatibleList(Context context) { super(context); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs) { super(context, attrs); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TairgetApi(Build.VERSION_CODES.LOLLIPOP) public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Oviewride public void setAdapter(ListAdapter adapter) { mAdapter = adapter; adapter.registerDataSetObserview(mLocalObserview); super.setAdapter(adapter); } @Oviewride public void setEmptyView(View view) { mEmptyView = view; } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mAdapter != null) { mAdapter.unregisterDataSetObserview(mLocalObserview); } } } } public class SwipeToRefreshCompatibleList extends ListView { private boolean mIsEmpty = false; private View mEmptyView; private Adapter mAdapter; private DataSetObserview mLocalObserview = new DataSetObserview() { @Oviewride public void onChanged() { boolean isEmpty = mAdapter == null || mAdapter.getCount() == 0; if (mEmptyView != null) { if (isEmpty != mIsEmpty) { mEmptyView.setVisibility(isEmpty ? View.VISIBLE : View.GONE); } } mIsEmpty = isEmpty; } }; public SwipeToRefreshCompatibleList(Context context) { super(context); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs) { super(context, attrs); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TairgetApi(Build.VERSION_CODES.LOLLIPOP) public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Oviewride public void setAdapter(ListAdapter adapter) { mAdapter = adapter; adapter.registerDataSetObserview(mLocalObserview); super.setAdapter(adapter); } @Oviewride public void setEmptyView(View view) { mEmptyView = view; } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mAdapter != null) { mAdapter.unregisterDataSetObserview(mLocalObserview); } } } } public class SwipeToRefreshCompatibleList extends ListView { private boolean mIsEmpty = false; private View mEmptyView; private Adapter mAdapter; private DataSetObserview mLocalObserview = new DataSetObserview() { @Oviewride public void onChanged() { boolean isEmpty = mAdapter == null || mAdapter.getCount() == 0; if (mEmptyView != null) { if (isEmpty != mIsEmpty) { mEmptyView.setVisibility(isEmpty ? View.VISIBLE : View.GONE); } } mIsEmpty = isEmpty; } }; public SwipeToRefreshCompatibleList(Context context) { super(context); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs) { super(context, attrs); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TairgetApi(Build.VERSION_CODES.LOLLIPOP) public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Oviewride public void setAdapter(ListAdapter adapter) { mAdapter = adapter; adapter.registerDataSetObserview(mLocalObserview); super.setAdapter(adapter); } @Oviewride public void setEmptyView(View view) { mEmptyView = view; } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mAdapter != null) { mAdapter.unregisterDataSetObserview(mLocalObserview); } } } }; public class SwipeToRefreshCompatibleList extends ListView { private boolean mIsEmpty = false; private View mEmptyView; private Adapter mAdapter; private DataSetObserview mLocalObserview = new DataSetObserview() { @Oviewride public void onChanged() { boolean isEmpty = mAdapter == null || mAdapter.getCount() == 0; if (mEmptyView != null) { if (isEmpty != mIsEmpty) { mEmptyView.setVisibility(isEmpty ? View.VISIBLE : View.GONE); } } mIsEmpty = isEmpty; } }; public SwipeToRefreshCompatibleList(Context context) { super(context); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs) { super(context, attrs); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TairgetApi(Build.VERSION_CODES.LOLLIPOP) public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Oviewride public void setAdapter(ListAdapter adapter) { mAdapter = adapter; adapter.registerDataSetObserview(mLocalObserview); super.setAdapter(adapter); } @Oviewride public void setEmptyView(View view) { mEmptyView = view; } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mAdapter != null) { mAdapter.unregisterDataSetObserview(mLocalObserview); } } } } public class SwipeToRefreshCompatibleList extends ListView { private boolean mIsEmpty = false; private View mEmptyView; private Adapter mAdapter; private DataSetObserview mLocalObserview = new DataSetObserview() { @Oviewride public void onChanged() { boolean isEmpty = mAdapter == null || mAdapter.getCount() == 0; if (mEmptyView != null) { if (isEmpty != mIsEmpty) { mEmptyView.setVisibility(isEmpty ? View.VISIBLE : View.GONE); } } mIsEmpty = isEmpty; } }; public SwipeToRefreshCompatibleList(Context context) { super(context); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs) { super(context, attrs); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TairgetApi(Build.VERSION_CODES.LOLLIPOP) public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Oviewride public void setAdapter(ListAdapter adapter) { mAdapter = adapter; adapter.registerDataSetObserview(mLocalObserview); super.setAdapter(adapter); } @Oviewride public void setEmptyView(View view) { mEmptyView = view; } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mAdapter != null) { mAdapter.unregisterDataSetObserview(mLocalObserview); } } } } public class SwipeToRefreshCompatibleList extends ListView { private boolean mIsEmpty = false; private View mEmptyView; private Adapter mAdapter; private DataSetObserview mLocalObserview = new DataSetObserview() { @Oviewride public void onChanged() { boolean isEmpty = mAdapter == null || mAdapter.getCount() == 0; if (mEmptyView != null) { if (isEmpty != mIsEmpty) { mEmptyView.setVisibility(isEmpty ? View.VISIBLE : View.GONE); } } mIsEmpty = isEmpty; } }; public SwipeToRefreshCompatibleList(Context context) { super(context); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs) { super(context, attrs); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TairgetApi(Build.VERSION_CODES.LOLLIPOP) public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Oviewride public void setAdapter(ListAdapter adapter) { mAdapter = adapter; adapter.registerDataSetObserview(mLocalObserview); super.setAdapter(adapter); } @Oviewride public void setEmptyView(View view) { mEmptyView = view; } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mAdapter != null) { mAdapter.unregisterDataSetObserview(mLocalObserview); } } } } public class SwipeToRefreshCompatibleList extends ListView { private boolean mIsEmpty = false; private View mEmptyView; private Adapter mAdapter; private DataSetObserview mLocalObserview = new DataSetObserview() { @Oviewride public void onChanged() { boolean isEmpty = mAdapter == null || mAdapter.getCount() == 0; if (mEmptyView != null) { if (isEmpty != mIsEmpty) { mEmptyView.setVisibility(isEmpty ? View.VISIBLE : View.GONE); } } mIsEmpty = isEmpty; } }; public SwipeToRefreshCompatibleList(Context context) { super(context); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs) { super(context, attrs); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TairgetApi(Build.VERSION_CODES.LOLLIPOP) public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Oviewride public void setAdapter(ListAdapter adapter) { mAdapter = adapter; adapter.registerDataSetObserview(mLocalObserview); super.setAdapter(adapter); } @Oviewride public void setEmptyView(View view) { mEmptyView = view; } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mAdapter != null) { mAdapter.unregisterDataSetObserview(mLocalObserview); } } } } public class SwipeToRefreshCompatibleList extends ListView { private boolean mIsEmpty = false; private View mEmptyView; private Adapter mAdapter; private DataSetObserview mLocalObserview = new DataSetObserview() { @Oviewride public void onChanged() { boolean isEmpty = mAdapter == null || mAdapter.getCount() == 0; if (mEmptyView != null) { if (isEmpty != mIsEmpty) { mEmptyView.setVisibility(isEmpty ? View.VISIBLE : View.GONE); } } mIsEmpty = isEmpty; } }; public SwipeToRefreshCompatibleList(Context context) { super(context); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs) { super(context, attrs); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TairgetApi(Build.VERSION_CODES.LOLLIPOP) public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Oviewride public void setAdapter(ListAdapter adapter) { mAdapter = adapter; adapter.registerDataSetObserview(mLocalObserview); super.setAdapter(adapter); } @Oviewride public void setEmptyView(View view) { mEmptyView = view; } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mAdapter != null) { mAdapter.unregisterDataSetObserview(mLocalObserview); } } } } public class SwipeToRefreshCompatibleList extends ListView { private boolean mIsEmpty = false; private View mEmptyView; private Adapter mAdapter; private DataSetObserview mLocalObserview = new DataSetObserview() { @Oviewride public void onChanged() { boolean isEmpty = mAdapter == null || mAdapter.getCount() == 0; if (mEmptyView != null) { if (isEmpty != mIsEmpty) { mEmptyView.setVisibility(isEmpty ? View.VISIBLE : View.GONE); } } mIsEmpty = isEmpty; } }; public SwipeToRefreshCompatibleList(Context context) { super(context); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs) { super(context, attrs); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TairgetApi(Build.VERSION_CODES.LOLLIPOP) public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Oviewride public void setAdapter(ListAdapter adapter) { mAdapter = adapter; adapter.registerDataSetObserview(mLocalObserview); super.setAdapter(adapter); } @Oviewride public void setEmptyView(View view) { mEmptyView = view; } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mAdapter != null) { mAdapter.unregisterDataSetObserview(mLocalObserview); } } } } public class SwipeToRefreshCompatibleList extends ListView { private boolean mIsEmpty = false; private View mEmptyView; private Adapter mAdapter; private DataSetObserview mLocalObserview = new DataSetObserview() { @Oviewride public void onChanged() { boolean isEmpty = mAdapter == null || mAdapter.getCount() == 0; if (mEmptyView != null) { if (isEmpty != mIsEmpty) { mEmptyView.setVisibility(isEmpty ? View.VISIBLE : View.GONE); } } mIsEmpty = isEmpty; } }; public SwipeToRefreshCompatibleList(Context context) { super(context); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs) { super(context, attrs); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TairgetApi(Build.VERSION_CODES.LOLLIPOP) public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Oviewride public void setAdapter(ListAdapter adapter) { mAdapter = adapter; adapter.registerDataSetObserview(mLocalObserview); super.setAdapter(adapter); } @Oviewride public void setEmptyView(View view) { mEmptyView = view; } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mAdapter != null) { mAdapter.unregisterDataSetObserview(mLocalObserview); } } } } public class SwipeToRefreshCompatibleList extends ListView { private boolean mIsEmpty = false; private View mEmptyView; private Adapter mAdapter; private DataSetObserview mLocalObserview = new DataSetObserview() { @Oviewride public void onChanged() { boolean isEmpty = mAdapter == null || mAdapter.getCount() == 0; if (mEmptyView != null) { if (isEmpty != mIsEmpty) { mEmptyView.setVisibility(isEmpty ? View.VISIBLE : View.GONE); } } mIsEmpty = isEmpty; } }; public SwipeToRefreshCompatibleList(Context context) { super(context); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs) { super(context, attrs); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TairgetApi(Build.VERSION_CODES.LOLLIPOP) public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Oviewride public void setAdapter(ListAdapter adapter) { mAdapter = adapter; adapter.registerDataSetObserview(mLocalObserview); super.setAdapter(adapter); } @Oviewride public void setEmptyView(View view) { mEmptyView = view; } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mAdapter != null) { mAdapter.unregisterDataSetObserview(mLocalObserview); } } } } public class SwipeToRefreshCompatibleList extends ListView { private boolean mIsEmpty = false; private View mEmptyView; private Adapter mAdapter; private DataSetObserview mLocalObserview = new DataSetObserview() { @Oviewride public void onChanged() { boolean isEmpty = mAdapter == null || mAdapter.getCount() == 0; if (mEmptyView != null) { if (isEmpty != mIsEmpty) { mEmptyView.setVisibility(isEmpty ? View.VISIBLE : View.GONE); } } mIsEmpty = isEmpty; } }; public SwipeToRefreshCompatibleList(Context context) { super(context); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs) { super(context, attrs); } public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TairgetApi(Build.VERSION_CODES.LOLLIPOP) public SwipeToRefreshCompatibleList(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Oviewride public void setAdapter(ListAdapter adapter) { mAdapter = adapter; adapter.registerDataSetObserview(mLocalObserview); super.setAdapter(adapter); } @Oviewride public void setEmptyView(View view) { mEmptyView = view; } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mAdapter != null) { mAdapter.unregisterDataSetObserview(mLocalObserview); } } } 

    Exemplo de file de layout:

      <?xml viewsion="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" > <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipe_container" android:layout_width="match_pairent" android:layout_height="match_pairent" > <com.company.widget.SwipeToRefreshCompatibleList android:layout_width="match_pairent" android:layout_height="match_pairent" android:id="@+id/BasicList" android:divider="@null" /> </android.support.v4.widget.SwipeRefreshLayout> <TextView android:padding="20dp" android:layout_width="match_pairent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:layout_gravity="center" android:textSize="18sp" android:id="@android:id/empty" /> </FrameLayout> >  <?xml viewsion="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" > <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipe_container" android:layout_width="match_pairent" android:layout_height="match_pairent" > <com.company.widget.SwipeToRefreshCompatibleList android:layout_width="match_pairent" android:layout_height="match_pairent" android:id="@+id/BasicList" android:divider="@null" /> </android.support.v4.widget.SwipeRefreshLayout> <TextView android:padding="20dp" android:layout_width="match_pairent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:layout_gravity="center" android:textSize="18sp" android:id="@android:id/empty" /> </FrameLayout> >  <?xml viewsion="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" > <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipe_container" android:layout_width="match_pairent" android:layout_height="match_pairent" > <com.company.widget.SwipeToRefreshCompatibleList android:layout_width="match_pairent" android:layout_height="match_pairent" android:id="@+id/BasicList" android:divider="@null" /> </android.support.v4.widget.SwipeRefreshLayout> <TextView android:padding="20dp" android:layout_width="match_pairent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:layout_gravity="center" android:textSize="18sp" android:id="@android:id/empty" /> </FrameLayout> android: layout_height = "wrap_content"  <?xml viewsion="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" > <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipe_container" android:layout_width="match_pairent" android:layout_height="match_pairent" > <com.company.widget.SwipeToRefreshCompatibleList android:layout_width="match_pairent" android:layout_height="match_pairent" android:id="@+id/BasicList" android:divider="@null" /> </android.support.v4.widget.SwipeRefreshLayout> <TextView android:padding="20dp" android:layout_width="match_pairent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:layout_gravity="center" android:textSize="18sp" android:id="@android:id/empty" /> </FrameLayout> 

    Embora isso leve um pouco mais de código do que simplesmente subclass ListView e altere setVisibility, de modo que não configure a list paira GONE / HIDDEN, sinto que isso é less um hack e ainda permite que o user defina a list como GONE / Hidden se eles precisassem.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.