Simple application of Viewpager

Source: Internet
Author: User

The simple use of the Viewpager cycle, such as a large number of Viewpager, Basepageradapter cannot be very large data, can be used in a circular way to solve, Viewpager will always preload the back interface, So let the control itself find the view and the data

package cn.new1.cloudnurse.pregnancy.main.adapter;public class wikipediapageradapter  extends basepageradapter{     //layout of the view private list<scrollview>  contentViewList = new LinkedList<ScrollView> (); private int  Number of pagercount;    //loops  Context context;  public  Wikipediapageradapter (Context context, int pagercount)  {  this.context =  context;  this.pagerCount = pagerCount;// * 2;  for  (int  i = 0; i < pagercount; i++)  {   ScrollView  scrollview =   (ScrollView)  view.inflate (context, r.layout.wikipedia_pager_item,  NULL);    contentviewlist.add (ScrollView);  } }  wikipediadata  date;  @Override  public void draw(INT&NBSP;ARG0,&NBSP;OBJECT&NBSP;ARG1)  {//  wikipediadata date;  try {    jsonobject jsonobject = new jsonobject (String) arg1);    Date = new wikipediadata (); = jsonobject.optstring (" CurrentDate ");    date.babychange = jsonobject.optstring (" V_baby_changes ");    date.momchange = jsonobject.optstring ("V_mom_changes");       showview (date);  } catch  (jsonexception e)  {    E.printstacktrace ();   }   }  private void showview (final  Wikipediadata date) {  //Gets the view of the corresponding data and then loads the data display   ScrollView scrollView =  Contentviewlist.get (Date.index%pagercount);    datetv =  (TextView)   Scrollview.findviewbyid (;  &nbSp;babychangetv = findview.byid (scrollview,;  });     datetv.settext (;   babychangetv.settext (Date.babychange); }       @Override  public int getcount ()  {  return  pregnancyparam.gestational_day_count;    //countless to ensure that the number of Viewpager can always accumulate  }  @Override  public boolean isviewfromobject (view view, object obj)  {  return  view == obj; } private textview datetv;   //Date  private  textview babychangetv; //Baby Change    public static int indexcurrent  = 0;  @Override  public object instantiateitem (view view, int  Index)  {  //view  viewgroup parent =  (ViewGroup) to initialize   Contentviewlist.get (Index%pagercount). GetParent ();             wikipediadb db = new &NBSP;WIKIPEDIADB (context);   wikipediadata tmpdata = db.getcontactlist (index+ "");     if  (parent != null)  {    //cyclic queue loading   Partial memory will be the same   It is best to ensure that no adjacent  viewpager memory is cached in real time 3 interfaces      } else {    ( Viewpager)  view). AddView (Contentviewlist.get (Index%pagercount), 0);  }     Indexcurrent = index%pagercount;    return contentviewlist.get (index% Pagercount); }  @Override  public void destroyitem (View view, int index,  object obj)  {   ((Viewpager)  view). Removeview (Contentviewlist.get (index% Pagercount))   //remove view }   @Override  public int getitemposition (Object  object)  {  //&nbsp todo auto-generated method stub  return position_unchanged; }  }

Simple application of Viewpager

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.