Reputation: 3404
I want to add a fragment for a sliding drawer in DrawerLayout. Means the last child of DrawerLayout is to be a fragment. And When I click on Drawer ico, the fragment to be visible in Drawer. But When i try, I couldn't get the view of the fragment in Activity. Please help me for doing it.
Thanks Jomia
Upvotes: 0
Views: 371
Reputation: 3404
I got the solution.
In layout,
<fragment
android:name="com.example.fragments.MyFragment "
android:id="@+id/left_drawer"
android:layout_weight="1"
android:layout_width="240dp"
android:layout_gravity="right"
android:layout_height="match_parent"/>
In activity,
MyFragment myFragment = (MyFragment) getFragmentManager().findFragmentById(R.id.left_drawer); View fragmentView = myFragment .getView();
Then I just use this view in onPrepareOptionsMenu for drawer.
@Override
public boolean onPrepareOptionsMenu(Menu menu)
{
boolean isDrawerOpen= dLayout.isDrawerOpen(fragmentView );
if(isDrawerOpen)
menu.findItem(R.id.drawer).setVisible(false);
else
menu.findItem(R.id.drawer).setVisible(true);
return super.onPrepareOptionsMenu(menu);
}
Thats all...
Upvotes: 1