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.
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 .
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.
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.
This is SwipeRefreshLayout
. Version 21 of the support library includes it replacing the old style.
Detailed guide could be found here: http://antonioleiva.com/swiperefreshlayout/
Plus for ListView I recommend to read about canChildScrollUp() in the comments ;)
I like this guide the best and its really easy to understand: https://www.bignerdranch.com/blog/implementing-swipe-to-refresh/
Add the following to gradle:
compile 'com.android.support:support-v4:22.2.0'
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>
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);
});
}
}
Don't forget to call mSwipeRefreshLayout.setRefreshing(false); once your refreshing ends.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With