在导航抽屉中,如何从片段调用片段时刷新标题和抽屉列表? [英] In Navigation drawer, how to refresh title and drawerlist when calling fragment from fragment?

查看:80
本文介绍了在导航抽屉中,如何从片段调用片段时刷新标题和抽屉列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个愚蠢的问题,我正在为我的android应用程序使用导航抽屉.所以到目前为止一切都很好.但是现在我需要从一个片段中调用另一个片段.我可以成功替换该片段,但是我不知道如何更改操作栏标题和抽屉列表选择.

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.

例如: 在抽屉列表中,我有"frag 1"和"frag 2" 所以在MainActivity中,我有

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.

但是现在我需要从"frag 1"中的按钮调用"frag 2".我可以将片段替换为"frag 2".但是,一旦我更改了片段,操作栏标题仍然是"frag 1",并且抽屉列表仍然显示我选择了"frag 1".我应该如何改变呢?我不能从片段中调用mainActivity中的函数,可以吗?

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 ?

推荐答案

实际上,我自己找到了答案.我可以使用以下命令从片段中调用parentActivity函数:

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

((ParentActivityClassName)getActivity()).parentPublicMethod();

这篇关于在导航抽屉中,如何从片段调用片段时刷新标题和抽屉列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆