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 constructor

  • newinstance() takes parameters, puts them in bundle, , attaches bundle newly-constructed instance of fragment via setarguments()

  • your fragment, when needs data, calls getarguments() retrieve bundle

this ensures data survive configuration changes.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -