0

I am using SwipeRefreshLayout and everything is fine, when Listview has some childs. Problem is: when listView has no chileds it does not show load indicator after setRefreshing(true) call. How to fix it?

Yarh
  • 4,459
  • 5
  • 45
  • 95

2 Answers2

9

It actually does show the indicator...behind the ActionBar!

The way I fixed it was below:

    Display display = getActivity().getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int height = size.y;
    getSwipeRefreshLayout().setProgressViewOffset(false, -200, height / 9);

EDIT

The above is no longer the correct answer. The correct answer is below:

getSwipeRefreshLayout().post(new Runnable() {
    @Override public void run() {
        getSwipeRefreshLayout().setRefreshing(true);
    }
});
KVISH
  • 12,923
  • 17
  • 86
  • 162
1

How to fix it?

I faced the same issue. My fix was to provide an empty view for the ListView, wrapped around a ScrollView and a SwipeRefreshLayout. Something lie:

  <android.support.v4.widget.SwipeRefreshLayout        
       xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:tools="http://schemas.android.com/tools"
       android:layout_width="match_parent"
       android:id="@android:id/empty"
       android:layout_height="match_parent" >

       <ScrollView
          android:layout_width="match_parent"
          android:layout_height="wrap_content" >
          <View                    
             android:layout_width="match_parent"
             android:layout_height="wrap_content" />
       </ScrollView>
   </android.support.v4.widget.SwipeRefreshLayout>
Blackbelt
  • 156,034
  • 29
  • 297
  • 305