In Navigation drawer, how to refresh title and dra

2020-05-01 09:35发布

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条回答
Ridiculous、
2楼-- · 2020-05-01 10:05

Actually I found the answer myself. I can call parentActivity function from fragment by using:

((ParentActivityClassName)getActivity()).parentPublicMethod();
查看更多
登录 后发表回答