android - Viewpager pages with different layouts but same fragment class -
using viewpager, i'm working on guide tells user how use app.
this how add/setup pages:
... private class screenslidepageradapter extends fragmentstatepageradapter { public screenslidepageradapter(fragmentmanager fm) { super(fm); } @override public fragment getitem(int position) { switch (position) { case 0: return new guide_fragment(); case 1: return new guide_fragment_2(); case 2,3,4 etc. default: return null; } } ...
but way have have fragment class each page, , since pages images , text, figured might not necessary.
is there way can use same fragment class pages , assign different layouts it?
thanks
is there way can use same fragment class pages , assign different layouts it?
sure. pass data fragment indicating display, typically via factory pattern:
create static
newinstance()
method takes data might ordinarily pass fragment constructornewinstance()
takes parameters, puts them inbundle
, , attachesbundle
newly-constructed instance of fragment viasetarguments()
your fragment, when needs data, calls
getarguments()
retrievebundle
this ensures data survive configuration changes.
Comments
Post a Comment