Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere to Async in PagerAdatper
    text
    copied!<p>My fragment activity used this adapter to display all the result in a listview. The page will have a title tab and each tab will have the list result. <br>Now the list result I read from internal storage and each time I swipe to next page it will have slight lag or delay, so I am thinking implementing ASYNCTask inside this pageradapter so the experience will be better but I have no idea where to implement. Could you guys point me out?? </p> <pre><code>public class ViewPagerAdapter extends PagerAdapter { public ViewPagerAdapter( Context context ) { //This is where i get my title for (HashMap&lt;String, String&gt; channels : allchannel){ String title = channels.get(KEY_TITLE); titles[acc] = title; acc++; } scrollPosition = new int[titles.length]; for ( int i = 0; i &lt; titles.length; i++ ) { scrollPosition[i] = 0; } } @Override public String getPageTitle( int position ) { return titles[position]; } @Override public int getCount() { return titles.length; } @Override public Object instantiateItem( View pager, final int position ) { String filename = null; ListView v = new ListView( context ); final ArrayList&lt;HashMap&lt;String, String&gt;&gt; items = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); DatabaseHandler db = new DatabaseHandler(context); filename = openFile("PAGE1"); //OpenFile function is read file from internal storage switch(position){ case 0: filename = openFile("PAGE1"); break; case 1: filename = openFile("PAGE2"); break; case 2: filename = openFile("PAGE3"); break; } try{ //Use json to read internal storage file(Page1/Page2) and display all the result on the list } }catch(Exception e){ } ListAdapter listadapter=new ListAdapter(context, items); v.setAdapter( listadapter ); ((ViewPager)pager ).addView( v, 0 ); return v; } @Override public void destroyItem( View pager, int position, Object view ) { ( (ViewPager) pager ).removeView( (ListView) view ); } @Override public boolean isViewFromObject( View view, Object object ) { return view.equals( object ); } @Override public void finishUpdate( View view ) { } @Override public void restoreState( Parcelable p, ClassLoader c ) { if ( p instanceof ScrollState ) { scrollPosition = ( (ScrollState) p ).getScrollPos(); } } @Override public Parcelable saveState() { return new ScrollState( scrollPosition ); } @Override public void startUpdate( View view ) { } </code></pre> <p>}</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