android - how to set layout for a fragment? -
it's multi tap activity >> i'm trying set layout each tab doesnt work ! shows nothing in both tabs !
here's code
public class game extends activity { public static context appcontext; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.game); //actionbar gets initiated actionbar actionbar = getactionbar(); //tell actionbar want use tabs. actionbar.setnavigationmode(actionbar.navigation_mode_tabs); //initiating both tabs , set text it. actionbar.tab roundtab = actionbar.newtab().settext("round 55"); actionbar.tab scoretab = actionbar.newtab().settext("score 55"); //create 2 fragments want use display content fragment roundfragment = new roundfragment(); fragment scorefragment = new scorefragment(); //set tab listener. can listen clicks. roundtab.settablistener(new mytabslistener(roundfragment)); scoretab.settablistener(new mytabslistener(scorefragment)); //add 2 tabs actionbar actionbar.addtab(roundtab); actionbar.addtab(scoretab); } class mytabslistener implements actionbar.tablistener { public fragment fragment; public mytabslistener(fragment fragment) { this.fragment = fragment; } public void ontabreselected(tab tab, fragmenttransaction ft) { } public void ontabselected(tab tab, fragmenttransaction ft) { } public void ontabunselected(tab tab, fragmenttransaction ft) { } } public class roundfragment extends fragment { @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment return inflater.inflate(r.layout.round, container, false); } } public class scorefragment extends fragment { @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment return inflater.inflate(r.layout.score, container, false); } } }
your ontabselected()
empty. that's why shows nothing on selection.
add code ontabselected()
of mytabslistener
.
public void ontabselected(tab tab, fragmenttransaction ft) { ft.add([id container /viewgroup in have load fragment],fragment) }
Comments
Post a Comment