Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Lollipop - Pull to refresh

I am trying to implement pull-to-refresh in Android. I know there is SwipeRefreshLayout but with all the newly designed Google apps like Drive (see attached) for Lollipop, I have noticed there is a new refresh icon that comes in the view when pulled. I tried looking it online but in vain. Has Android released this as a part of the Material Design? Any ideas about how to implement it?

EDIT: Some people have pointed out how this is a duplicate of How to implement a Pull-to-refresh. It is not the same question. You'll see it if you read the question properly.

enter image description here

like image 974
gsb Avatar asked Nov 07 '14 18:11

gsb


People also ask

How do you swipe to refresh on Android?

To add the swipe to refresh widget to an existing app, add SwipeRefreshLayout as the parent of a single ListView or GridView . Remember that SwipeRefreshLayout only supports a single ListView or GridView child. You can also use the SwipeRefreshLayout widget with a ListFragment .

How do you use pull to refresh?

Pull-to-refresh is a touchscreen gesture that consists of touching the screen of a computing device with a finger or pressing a button on a pointing device, dragging the screen downward with the finger or pointing device, and then releasing it, as a signal to the application to refresh the contents of the screen.

How do I turn off swipe refresh?

You can also use 'Find in page' option for automatic searching by tapping on 3 dots on upper right corner of the screen . Tap on Find in page for automatic searching. In “The pull-to-refresh effect Android” , click on Disable button. Select 'Always' and tap on RELAUNCH NOW button to disable pull-to-refresh feature.


4 Answers

This is SwipeRefreshLayout . Version 21 of the support library includes it replacing the old style.

like image 120
Ben Pye Avatar answered Oct 18 '22 04:10

Ben Pye


  1. Download the latest Lollipop SDK and Extras/Android support library
  2. Set Project's Build Target to Android 5.0 (otherwise support package can have errors with resources)
  3. Update your libs/android-support-v4.jar to 21st version
  4. Use android.support.v4.widget.SwipeRefreshLayout plus android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener

Detailed guide could be found here: http://antonioleiva.com/swiperefreshlayout/

Plus for ListView I recommend to read about canChildScrollUp() in the comments ;)

like image 22
goRGon Avatar answered Oct 18 '22 03:10

goRGon


I like this guide the best and its really easy to understand: https://www.bignerdranch.com/blog/implementing-swipe-to-refresh/

  1. Add the following to gradle:

    compile 'com.android.support:support-v4:22.2.0'

  2. Add the swipe to refresh to your layout - put in listview or recyclerview in the middle of the swiperefreshlayout:

        <ListView
            android:id="@+id/activity_main_listview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >
        </ListView>
    
    </android.support.v4.widget.SwipeRefreshLayout>
    
  3. Add in your code for the mainactivity:

    public class MainActivity extends Activity {
    
    ListView mListView;
    SwipeRefreshLayout mSwipeRefreshLayout;
    Adapter mAdapter;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.acivity_main);
      SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.activity_main_swipe_refresh_layout);
      mListView = findViewById(R.id.activity_main_list_view);
      mListView.setAdapter(new ArrayAdapter<String>(){
      String[] fakeTweets = getResources().getStringArray(R.array.fake_tweets);
      mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, fakeTweets)
      listView.setAdapter(mAdapter);
    });
    }
    

    }

  4. Don't forget to call mSwipeRefreshLayout.setRefreshing(false); once your refreshing ends.

like image 7
Simon Avatar answered Oct 18 '22 02:10

Simon


hi If you wan't to develop such a kind of Layout then please follow this url, i was used it it's an awesome.

https://github.com/stormzhang/SwipeRefreshLayoutDemo

like image 4
Rajan Bhavsar Avatar answered Oct 18 '22 03:10

Rajan Bhavsar