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

How to start daemon on android by adb -

testing - Detect whether test has failed within fixture -

Angularjs unit testing - ng-disabled not working when adding text to textarea -