Joah Theron
Joah Theron

Reputation: 15

How to minimize sliding menu after clicking an button

I'm using https://github.com/jfeinstein10/SlidingMenu this SlidingMenu. I have a simple problem, I want to slide the menu to the left side after clicking a button on the Slidemenu. I used the sample program from jfeinstein10 and changed it for my usage.

Here are pictures.

Picture

enter image description here

If you still have questions write them down pls. Thx for help.

public class AnmeldenFragment extends SherlockFragment {
    @Override
    public View onCreateView(LayoutInflater inflater, 
       ViewGroup container, Bundle savedInstanceState) {


        View view =  inflater.inflate(R.layout.activity_anmelden, container, false);
        return view;
   }
}

this is my Fragment and I want to close the Slide menu after return view. It shows the new Fragment but it dont close the slide menu.

Upvotes: 1

Views: 834

Answers (2)

BAZTED
BAZTED

Reputation: 546

You can get access to SlidingMenu object. Create method which will handle your action.

Example:

LeftMenuFragment.java:

    private void elementPressed(int position){
        if (getActivity() instanceof YourSlidingMenuActivity) {//check if fragment attached to correct Activity which extends SlidingMenuActivity
            YourSlidingMenuActivity activity = (YourSlidingMenuActivity) getActivity(); //cast your activity

            if (activity.getSlidingMenu().isMenuShowing()) { // check if menu is visible
                activity.toggle();//method to close/open 
            }
        }
        }

Upvotes: 0

Ketan Ahir
Ketan Ahir

Reputation: 6728

You have to use interface to communicate between fragment and activity then try this method to toggle menu menu.toggle(); Complete Tutorial

Upvotes: 1

Related Questions