Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes PullToRefresh work with FragmentPagerAdapter?
    text
    copied!<p><strong>Libraries:</strong></p> <ul> <li><a href="https://github.com/chrisbanes/Android-PullToRefresh" rel="nofollow">https://github.com/chrisbanes/Android-PullToRefresh</a></li> <li><a href="https://github.com/JakeWharton/Android-ViewPagerIndicator" rel="nofollow">https://github.com/JakeWharton/Android-ViewPagerIndicator</a></li> </ul> <p>In the Sample <code>PullToRefreshListInViewPagerActivity</code> only works with PageAdapter.</p> <p>I couldn't find a way to put it to work with <code>FragmentPageAdapter</code>.</p> <p><strong>Sample:</strong></p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ptr_list_in_vp); mViewPager = (ViewPager) findViewById(R.id.vp_list); mViewPager.setAdapter(new ListViewPagerAdapter()); } private class ListViewPagerAdapter extends PagerAdapter { @Override public View instantiateItem(ViewGroup container, int position) { Context context = container.getContext(); PullToRefreshListView plv = (PullToRefreshListView) LayoutInflater.from(context).inflate( R.layout.layout_listview_in_viewpager, container, false); ListAdapter adapter = new ArrayAdapter&lt;String&gt;(context, android.R.layout.simple_list_item_1, Arrays.asList(STRINGS)); plv.setAdapter(adapter); plv.setOnRefreshListener(PullToRefreshListInViewPagerActivity.this); // Now just add ListView to ViewPager and return it container.addView(plv, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); return plv; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View) object); } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } @Override public int getCount() { return 3; } } @Override public void onRefresh(PullToRefreshBase&lt;ListView&gt; refreshView) { new GetDataTask(refreshView).execute(); } private static class GetDataTask extends AsyncTask&lt;Void, Void, Void&gt; { PullToRefreshBase&lt;?&gt; mRefreshedView; public GetDataTask(PullToRefreshBase&lt;?&gt; refreshedView) { mRefreshedView = refreshedView; } @Override protected Void doInBackground(Void... params) { // Simulates a background job. try { Thread.sleep(4000); } catch (InterruptedException e) { } return null; } @Override protected void onPostExecute(Void result) { mRefreshedView.onRefreshComplete(); super.onPostExecute(result); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload