android - using same code for fragment and activity -


i have activity, want use fragment somewhere else, have rewrite entire class used both?

there needs 2 ways it, first way menu items fragments. second way in part of app needs go page same functions , appearance

you can write single fragment. , reuse in activity, not other way around.

with code below add fragment want container activity. don't forget check savedinstancestate if null in order see if creating or recreating activity.

 getsupportfragmentmanager()             .begintransaction()             .add(r.id.fragment_container, yourfragment.newinstance(), yourfragment.tag)             .commit(); 

Comments

Popular posts from this blog

AbotX : How do you create a parallel crawler that stays on and can be added to at run time from new requests -

testing - Detect whether test has failed within fixture -

android - Create single AAR file from multiple modules using Gradle -