Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Pull to Refresh using SwipeRefreshLayout like Gmail

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.39k
    Comment on it

    This blog provide you simple Pull to refresh functionality with SwipeRefreshLayout.

    1. First of all create new project.
    2. Open xml layout file and create ListView/ScrollView/Gridview.
    3. Wrap ListView/ScrollView/Gridview with "android.support.v4.widget.SwipeRefreshLayout" like

       < 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/listView"  
          android:layout_width="match_parent"  
          android:layout_height="match_parent"> 
      < /ListView>
      < /android.support.v4.widget.SwipeRefreshLayout>
      
    4. xml Layout part is finish here. Now open Activity class and initialize SwipeRefreshLayout and ListView.

    5. Set setOnRefreshListener to SwipeRefreshLayout and set refresh functionality in onRefresh() method.

      swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
      @Override
      public void onRefresh() {
      refrshAdapter();
      }
      });

    6 . set Color scheme to SwipeToRefresh.

    swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_red_light,android.R.color.holo_green_light,android.R.color.holo_purple,android.R.color.holo_blue_light);
    

    7 . Set SetRefreshing false when refresh functionality completed.

       swipeRefreshLayout.setRefreshing(false);
    

    Refrences:- SwipeToRefresh

    image1 image2

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: