android - Implententing a swipe view using a Fragment -


i designing constitution app , want use tabbed layout swipe view. tabs data database using custom adapter. since data size (no of fragment) unknown, want every swipe generate new view different chapter content constitution.

i want looks dictionary app below, swipe labels on both sides. familiar tabs love resource me achieve this, since documentation have seen doesn't explain this. thanks

enter image description here

modify desired output

oncreate

 arraylist<mcqquestionbean> mcqquestionbeans= new arraylist<mcqquestionbean>();         adapter = new newsfragmentpageradapter(getsupportfragmentmanager(),                 mcqquestionbeans, mcqtestactivity.this);         pager.setadapter(adapter); 

base adapter

public class newsfragmentpageradapter extends fragmentstatepageradapter {  private arraylist<mcqquestionbean> mcqquestionbeans;  private mcqquestionfragment fragment; private activity context;  public newsfragmentpageradapter(fragmentmanager fm, arraylist<mcqquestionbean> mcqquestionbeans, activity context) {     super(fm);     this.mcqquestionbeans = mcqquestionbeans;      this.context = context;  }  public void update(arraylist<mcqquestionbean> mcqquestionbeans) {     this.mcqquestionbeans = mcqquestionbeans;     notifydatasetchanged(); }  @override public int getcount() {     return mcqquestionbeans.size(); }  @override public int getitemposition(object object) {     // todo auto-generated method stub     return super.getitemposition(object); }  @override public fragment getitem(int position) {      fragment = mcqquestionfragment.newinstance(mcqquestionbeans.get(position), position, context);      return fragment;  }  } 

your fragment mcqquestionfragment

public class mcqquestionfragment extends fragment {  private int position, porrefid;     private string question;     private arraylist<mcqquestionchoicebean> choices;       @suppresswarnings("unchecked")     @override     public void oncreate(bundle savedinstancestate) {         // todo auto-generated method stub         super.oncreate(savedinstancestate);         position = getarguments().getint("position");         porrefid = getarguments().getint("porrefid");         usermarkedon = getarguments().getint("usermarkedon");         question = getarguments().getstring("question");         choices = (arraylist<mcqquestionchoicebean>) getarguments()                 .getserializable("choices");     }      public static mcqquestionfragment newinstance(             mcqquestionbean mcqquestionbean, int position, activity activity) {         final mcqquestionfragment f = new mcqquestionfragment();         final bundle args = new bundle();         args.putstring("question", mcqquestionbean.getquestion());         args.putint("position", position);         args.putint("usermarkedon", mcqquestionbean.getusercorrectedon());         args.putserializable("choices", mcqquestionbean.getchoices());         args.putint("porrefid", mcqquestionbean.getporrefid());         f.setarguments(args);          return f;     }  } 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

unity3d - Fatal error- Monodevelop-Unity failed to start -