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
Post a Comment