Closing FrameLayout for a Fragment in Android App -
i'm working on simple android app self-learning project. i've got lot of functioning, , have main activity has framelayout , recyclerview , floatingactionbutton stuff going on inside of it.
however, want make 1 of buttons in navigationdrawer open different view in framelayout using fragments. there way this, sort of making new fragment recyclerview , other stuff , putting recyclerview , floatingactionbutton in there?
i tried doing (when appropriate navigationdrawer button clicked):
statsfragment = new statsfragment(); fragmenttransaction transaction = getsupportfragmentmanager().begintransaction(); transaction.replace(r.id.rootlayout, statsfragment); transaction.addtobackstack(null); transaction.commit(); but caused app crash. pointers?
is r.id.rootlayout layout or fragment component?
if main activity has hard coded fragment (by hard coded mean declared in xml), no, can't change hard-coded fragment content fragmenttransaction. more information on this question's answer.
finally, can't put components 1 activity inside new fragment/activity since each component belongs 1 , only one context. see, activity extends context. when reference component declared in xml using activity.findviewbyid(int), making pointer determined view activity's layout, defined in oncreatemethod setcontentview(id). can't take pointer , throw fragment or activity within application without expecting problems. (well, maybe can, it's totally against best practices of android programming).
Comments
Post a Comment