Android support v4 SwipeRefreshLayout empty view issue

后端 未结 9 1138
耶瑟儿~
耶瑟儿~ 2021-01-01 18:01

SwipeRefresh is not working after setting an empty view for listview which is the only child of a SwipeRefresh layout. How to solve this issue?

9条回答
  •  执笔经年
    2021-01-01 18:43

    The problem for me was that when the empty view was visible then the refreshing circle wasn't shown although the refreshing method worked. For me this code worked, I hope it helps.

    • the xml layout:

      
      
          
      
          
      
              
          
      
      

    • the 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;
          }
      
          @Override
          public boolean canChildScrollUp() {
              if (mListView == null) {
                  return true;
              }
      
              return mListView.canScrollVertically(-1);
          }
      }
      
    • and in my Fragment where I use the layout I only set the swipe to refresh layout in this way:

      mSwipeRefreshLayout.setListView(mListView);
      
    • the ListView's empty view is set in this way:

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

    I hope it helps.

提交回复
热议问题