In Navigation drawer, how to refresh title and drawerlist when calling fragment from fragment?

无人久伴 提交于 2019-12-25 07:39:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!