0

I am having an activity which consists of Navigation View and fragments.

The fragment I am talking about is attached like this -- Activity <- Frag1 attached directly to Activity <- Frag2 gets its space when user on Frag1 wants that means on some user action.

When I am moving from frag1 to frag2 then I want to replace hamburger icon to a back button, which I achieved but just in the change of icon. The back button in the frag2 behaves just like the hamburger icon.

But I want it to behave as a back button which takes me from frag2 to frag1. Somehow I achieved the process of moving from frag2 to frag1 but then functionality of hamburger is lost. the way I did it is--

In main Activity this method is present which I can from frag2...

public void setHomeListener(View.OnClickListener listener){
    toolbar.setNavigationOnClickListener(listener);
}

This is the way I call above from frag2...

((MainActivity)getActivity()).setHomeListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(getActivity(), "Hello Boy2!!", Toast.LENGTH_SHORT).show();
            ((MainActivity)getActivity()).setHomeListener(null);
        }
    });

And after doing this I totally loose drawer functionality of hamburger icon. Please tell me how to correct this anyone.

Correct way-

public void setHomeListener(View.OnClickListener listener){
    toggle.setNavigationOnClickListener(listener);
}

0 Answers0