Note that there are some explanatory texts on larger screens.

plurals
  1. POGridView Loads Slowly After setAdapter() Is Called
    text
    copied!<p>I have <code>GridView</code>s laid across my 3 page <code>ViewPager</code>. The idea is to build a monthly view of a calendar that scrolls infinitely as far as the user wants.</p> <p>I based my work mostly off <a href="https://stackoverflow.com/users/127422/jon-willis">Jon Willis</a>' <a href="http://code.google.com/p/electricsleep/source/browse/trunk/src/com/androsz/electricsleepbeta/app/HistoryMonthActivity.java" rel="nofollow noreferrer">implementation</a> of infinite view paging. But instead of implementing my own <code>View</code> object; I'm using <code>GridView</code>s.</p> <p>Here's my implementation of the <code>onPageScrollStateChanged</code> method:</p> <pre><code>@Override public void onPageScrollStateChanged(int state) { if (state == ViewPager.SCROLL_STATE_IDLE) { FragmentPagerAdapter adapter = (FragmentPagerAdapter) mMonthPager .getAdapter(); // Called to obtain reference for the Fragments inside the ViewPager. CalendarGridMonthlyFragment oldMinMonthFragment = (CalendarGridMonthlyFragment) adapter .instantiateItem(mMonthPager, 0); CalendarGridMonthlyFragment oldMidMonthFragment = (CalendarGridMonthlyFragment) adapter .instantiateItem(mMonthPager, 1); CalendarGridMonthlyFragment oldMaxMonthFragment = (CalendarGridMonthlyFragment) adapter .instantiateItem(mMonthPager, 2); // Get the selected month for each Fragment. final Calendar oldMinMonth = oldMinMonthFragment.getSelectedMonth(); final Calendar oldMidMonth = oldMidMonthFragment.getSelectedMonth(); final Calendar oldMaxMonth = oldMaxMonthFragment.getSelectedMonth(); if (mFocusedPage == 0) { final Calendar newMonth = (Calendar) oldMinMonth.clone(); newMonth.add(Calendar.MONTH, -1); oldMinMonthFragment.setSelectedMonth(newMonth); oldMidMonthFragment.setSelectedMonth(oldMinMonth); oldMaxMonthFragment.setSelectedMonth(oldMidMonth); } else if (mFocusedPage == 2) { final Calendar newMonth = (Calendar) oldMaxMonth.clone(); newMonth.add(Calendar.MONTH, 1); oldMinMonthFragment.setSelectedMonth(oldMidMonth); oldMidMonthFragment.setSelectedMonth(oldMaxMonth); oldMaxMonthFragment.setSelectedMonth(newMonth); } mMonthPager.setCurrentItem(1, false); } } </code></pre> <p>And here's my <code>setSelectedMonth</code> method:</p> <pre><code>public void setSelectedMonth(Calendar value) { mMonth = value.get(Calendar.MONTH); mYear = value.get(Calendar.YEAR); CalendarGridMonthlyAdapter newAdapter = new CalendarGridMonthlyAdapter( mContext, GRID_CHIP, mGridWidth, mGridHeight, mMonth, mYear); mGridView.setAdapter(newAdapter); } </code></pre> <p>The infinite swiping works. But there's a noticeable flicker -- almost half a second -- after the scroll has finished.</p> <p>Debugging has shown me that <code>setAdapter</code> method is the culprit of all this fuss. So is there any way to speed up the process of setting new adapter?</p> <p>..or maybe another way of doing this?</p> <p>Thanks in advance!</p>
 

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