In Android applications such as Twitter (official app), when you encounter a ListView, you can pull it down (and it will bounce back when released) to refresh the content.
I wonder what is the best way, in your opinion, to implement that?
Some possibilities I could think of:
- An item on top of the ListView - however I don't think scrolling back to item position 1 (0-based) with animation on the ListView is an easy task.
- Another view outside the ListView - but I need to take care of moving the ListView position down when it is pulled, and I'm not sure if we can detect if the drag-touches to the ListView still really scroll the items on the ListView.
Any recommendations?
P.S. I wonder when the official Twitter app source code is released. It has been mentioned that it will be released, but 6 months has passed and we haven't heard about it since then.
Nobody have mention the new type of "Pull to refresh" which shows on top of the action bar like in the Google Now or Gmail application.
There is a library ActionBar-PullToRefresh which works exactly the same.
Finally, Google released an official version of pull-to-refresh library!
It is called
SwipeRefreshLayout
, inside the support library, and the documentation is here:1) Add
SwipeRefreshLayout
as a parent of view which will be treated as pull to refresh layout. (I tookListView
as an example, it can be anyView
likeLinearLayout
,ScrollView
etc.)2) Add a listener to your class
You can also call
pullToRefresh.setRefreshing(true/false);
as per your requirement.To get the latest Lollipop Pull-To Refresh:
android.support.v4.widget.SwipeRefreshLayout
plusandroid.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 ;)I think the best library is : https://github.com/chrisbanes/Android-PullToRefresh.
Works with:
I have very easy way to do this but now sure its the foolproof way There is my code PullDownListView.java
You just need to implement ListViewTouchEventListener on your activity where you want to use this ListView and set the listener
I have it implemented in PullDownListViewActivity
It works for me :)
If you don't want your program to look like an iPhone program that is force fitted into Android, aim for a more native look and feel and do something similar to Gingerbread: