android - Fragments - Do you have to use an Activity Wrapper around a fragment which comprises the whole Activity? -



android - Fragments - Do you have to use an Activity Wrapper around a fragment which comprises the whole Activity? -

consider sample app developers.android.com

this describes using fragments so:

on phone can utilize fragment 1 on activity , fragment 2 on activity b. on tablet have more real estate utilize fragment 1 , fragment 2 on activity a.

great! ... but... on first illustration (the 1 phone) create activity xml file containing single <fragment> , that's all, in activity phone call setcontentview() on xml? seems lot of redundant code (activity, xml & fragment display fragment): can set fragment activity or wrapper xml required?

ah, found here

public class mainmenuholder extends fragmentactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // if not added fragment manager add together it. if don't new fragment added every time method called (such on orientation change) if(savedinstancestate == null) getsupportfragmentmanager().begintransaction().add(android.r.id.content, new mainmenufragment()).commit(); } }

fragmentactivity allow's set fragment content of android.r.id.content assume android internal id of trunk view.

with method still end redundant activity (if want fragment acting activity). still, half much fluff having activity , xml file acting container.

any other answers appreciated!

android android-activity wrapper android-fragments

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -