Transaction of fragments in android results in blank screen -
if helps, want similar done in google tutorial
but there fragment created prior transition. if transition works fine; can't use approach
=====
aiming api 7+ trying have 1 fragment visible in whole screen , using button (a drawn button, ontouch event) alternate second fragment , viceversa.
but either blank screen when replace first fragment second, or if use fragmenttransaction.show , fragmenttransaction.hide; can switch 2 times before blank screen. dont want have on backstack.
i creating fragments in mainactivity's oncreate:
dicetable dicetable = new dicetable(); logger logger = new logger(); fragmenttransaction.add(dicetable, dicetable_tag); fragmenttransaction.add(logger, logger_tag); fragmenttransaction.add(r.id.fragment_container, logger); fragmenttransaction.add(r.id.fragment_container, dicetable);
then on 1 method (called fragments) switch:
logger logger = (logger)fragmentmanager.findfragmentbytag(logger_tag); dicetable dicetable = (dicetable)fragmentmanager.findfragmentbytag(dicetable_tag); if (dicetable.isvisible()) { fragmenttransaction.replace(r.id.fragment_container, logger); fragmenttransaction.commit(); fragmenttransaction.hide(dicetable); fragmenttransaction.show(logger); } else if (logger.isvisible()) { fragmenttransaction.replace(r.id.fragment_container, dicetable); fragmenttransaction.commit(); fragmenttransaction.hide(logger); fragmenttransaction.show(dicetable); }
this not how should this?
blank screen when replacing fragments
try initialize fragments in way:
private void initfragments() { mdicetable = new dicetable(); mlogger = new logger(); isdicetablevisible = true; fragmentmanager fm = getsupportfragmentmanager(); fragmenttransaction ft = fm.begintransaction(); ft.add(r.id.fragment_container, mdicetable); ft.add(r.id.fragment_container, mlogger); ft.hide(mlogger); ft.commit(); }
and flip between them in way:
private void flipfragments() { fragmentmanager fm = getsupportfragmentmanager(); fragmenttransaction ft = fm.begintransaction(); if (isdicetablevisible) { ft.hide(mdicetable); ft.show(mlogger); } else { ft.hide(mlogger); ft.show(mdicetable); } ft.commit(); isdicetablevisible = !isdicetablevisible; }
Comments
Post a Comment