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

sql - invalid in the select list because it is not contained in either an aggregate function -

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

How to start daemon on android by adb -