I'm using SwipeRefreshListener from the support libraries.  I am calling setRefresh from onPreExecute and onPostExecute of my AsyncTask.  However, nothing changes, there is no animation.  Is there something that I'm missing?  Are there certain setup parameters I need to set in order for it to work properly?
            Asked
            
        
        
            Active
            
        
            Viewed 1.6k times
        
    6
            
            
         
    
    
        crocboy
        
- 2,887
- 2
- 22
- 25
2 Answers
14
            This has worked for me, see more here: http://antonioleiva.com/swiperefreshlayout/
SwipeRefreshLayout: The layout you only need to decorate the swipable content (probable the whole layout) with this new layout. This view must be scrollable, such a ScrollView or a ListView. As a simple example:
<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TextView
            android:text="@string/hello_world"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:gravity="center"/>
    </ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
The code We just need to get the layout, and assign some colours and the listener. The refreshing listener is a post delayed handler.
 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
        swipeLayout.setOnRefreshListener(this);
        swipeLayout.setColorScheme(android.R.color.holo_blue_bright, 
                android.R.color.holo_green_light, 
                android.R.color.holo_orange_light, 
                android.R.color.holo_red_light);
    }
    @Override public void onRefresh() {
        new Handler().postDelayed(new Runnable() {
            @Override public void run() {
                swipeLayout.setRefreshing(false);
            }
        }, 5000);
    }
 
    
    
        Anderson K
        
- 5,445
- 5
- 35
- 50
- 
                    I didn't know SwipeRefreshLayout works only as parent of swipeable views thank you – MJ Studio Apr 29 '19 at 04:40
5
            
            
        //Please check this answers it hepls me : //SwipeRefreshLayout setRefreshing() not showing indicator initially //especially this
  mSwipeRefreshLayout.post(new Runnable() {
    @Override
    public void run() {
        mSwipeRefreshLayout.setRefreshing(true);
    } 
  });
 
    
    
        Community
        
- 1
- 1
 
    
    
        Yousef Zakher
        
- 1,634
- 15
- 18