android - How can I open a Fragment under the open NavigationDrawer with defining the Drawer in a separate fragment? -
android - How can I open a Fragment under the open NavigationDrawer with defining the Drawer in a separate fragment? -
my app opens navigationdrawer @ start. when user clicks on item in fragment beingness replaced.
for every item in navigation drawer have separate fragment. when user not take of options in navigationdrawer , closes it, main activit layout beingness shown.
i want 1 of own fragments brought when user closes side menu. (navigation drawer) npe when seek change
setcontentview(r.layout.activity_main);
with
setcontentview(r.layout.my_fragment);
(because cannot find navigation_drawer since defined in activity_main)
i don't set navigationdrawer in 1 of fragments, neither re-create fragment elements main.xml (it messy design :( ). supposed do? how supposed open desired fragment underneath navigationdrawer??
here oncreate in mainactivity:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mnavigationdrawerfragment = (fragmentnavigationdrawer) getsupportfragmentmanager().findfragmentbyid(r.id.navigation_drawer); mnavigationdrawerfragment.setup(r.id.navigation_drawer, (drawerlayout) findviewbyid(r.id.drawer_layout)); mtitle = gettitle(); }
here activity_main.xml
<!-- drawerlayout intended used top-level content view using match_parent both width , height consume total space available. -->
<!-- main content view, view below consumes entire space available using match_parent in both dimensions. --> <framelayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" /> <!-- android:layout_gravity="start" tells drawerlayout treat sliding drawer on left side left-to-right languages , on right side right-to-left languages. if you're not building against api 17 or higher, utilize android:layout_gravity="left" instead. --> <!-- drawer given fixed width in dp , extends total height of container. --> <fragment android:id="@+id/navigation_drawer" android:name="com.khoonat.khoonat.fragmentnavigationdrawer" android:layout_width="@dimen/navigation_drawer_width" android:layout_height="match_parent" android:layout_gravity="start" tools:layout="@layout/fragment_navigation_drawer" />
is bad solution? please note i'm kind of beginner :)
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); fragmentmanager fragmentmanager = getsupportfragmentmanager(); fragmentmanager.begintransaction().replace(r.id.container, fragmentsearchpropertylisting.newinstance(0)).commit(); mnavigationdrawerfragment = (fragmentnavigationdrawer) getsupportfragmentmanager().findfragmentbyid(r.id.navigation_drawer); mnavigationdrawerfragment.setup(r.id.navigation_drawer, (drawerlayout) findviewbyid(r.id.drawer_layout)); mtitle = gettitle(); }
the reddish arrow shows mean under navigation drawer.
android android-layout android-fragments navigation-drawer framelayout
Comments
Post a Comment