Android Lollipop - Pull To Refresh
Solution 1:
This is SwipeRefreshLayout
. Version 21 of the support library includes it replacing the old style.
Solution 2:
- Download the latest Lollipop SDK and Extras/Android support library
- Set Project's Build Target to Android 5.0 (otherwise support package can have errors with resources)
- Update your libs/android-support-v4.jar to 21st version
- 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 ;)
Solution 3:
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:
<ListViewandroid: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:
publicclassMainActivityextendsActivity { ListView mListView; SwipeRefreshLayout mSwipeRefreshLayout; Adapter mAdapter; @OverridepublicvoidonCreate(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(newArrayAdapter<String>(){ String[] fakeTweets = getResources().getStringArray(R.array.fake_tweets); mAdapter = newArrayAdapter<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.
Solution 4:
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.
Post a Comment for "Android Lollipop - Pull To Refresh"