问题
I have a dumb question that I'm using navigation drawer for my android app. so everything works well so far. But now I need to call another fragment from a fragment. I can successfully replace the fragment, but i don't know how to change the actionbar title and drawer list selection.
for example: in the drawerList i have "frag 1" and "frag 2" so in the MainActivity, i have
selectitem(position)
function to taking care of fragment replace, title change and also drawerlist selection change. So i can change fragment by clicking on different items on the drawerlist.
But now I need to call "frag 2" from a button in the "frag 1". I can replace the fragment to "frag 2". But once i change the fragment, the actionbar title is still "frag 1" and the drawerlist still show i'm select "frag 1". how should i change this? I can't call functions in the mainActivity from fragment, can i ?
回答1:
Actually I found the answer myself. I can call parentActivity function from fragment by using:
((ParentActivityClassName)getActivity()).parentPublicMethod();
来源:https://stackoverflow.com/questions/24535121/in-navigation-drawer-how-to-refresh-title-and-drawerlist-when-calling-fragment