Call an activity method from a fragment
From fragment to activty:
((YourActivityClassName)getActivity()).yourPublicMethod();
From activity to fragment:
FragmentManager fm = getSupportFragmentManager();
//if you added fragment via layout xml
YourFragmentClass fragment = (YourFragmentClass)fm.findFragmentById(R.id.your_fragment_id);
fragment.yourPublicMethod();
If you added fragment via code and used a tag string when you added your fragment, use findFragmentByTag instead:
YourFragmentClass fragment = (YourFragmentClass)fm.findFragmentByTag("yourTag");
Call an activity method from a fragment的更多相关文章
- .replace(R.id.container, new User()).commit();/The method replace(int, Fragment) in the type FragmentTransaction is not app
提示错误:The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arg ...
- 错误:The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, MyFragment)
Fragment newfragment =new MyFragment();fragmentTransaction.replace(R.layout.activity_main,newfragmen ...
- The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the arguments (int, SettingFragment, String)
The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the ...
- 通过Activity动态加载Fragment创建主界面构架
在做项目中,需要建立一个主界面框架,尝试过使用ViewPager ,后来又换成了使用Activity动态加载Fragment实现选项卡的效果.总结一下方便以后回顾. 先给出总体效果: 要实现上述效果, ...
- 【Android】安卓开发之activity如何传值到fragment,activity与fragment传值
作者:程序员小冰,GitHub主页:https://github.com/QQ986945193 新浪微博:http://weibo.com/mcxiaobing 大家知道,我们利用activity使 ...
- Activity中获取当前Fragment 中的子控件
XXXAdapter中 增加 public Fragment currentFragment; @Override public void setPrimaryItem(ViewGroup conta ...
- Tabbed Activity的使用(Fragment)
1,首先file -> new -> Activity -> Tabbed Activity 2,创建完成后,发现会自动的创建一大堆代码,大部分我们是不需要关心的,关于页面切换的代码 ...
- Android Activity生命周期以及Fragment生命周期的区别与分析
Android Fragment生命周期图: Activity生命周期图: 对照图: Fragment生命周期分析: 1. 当一个fragment被创建的时候,它会经历以下状态. onAttach() ...
- Activity被回收导致fragment的getActivity为null的解决办法
这两天一直被这个问题困扰,假如app长时间在后台运行,再点击进入会crash,而且fragment页面有重叠现象,让我十分不爽.研究了一天,终于明白其中的原理并加以解决.解决办法如下: 如果系统内存不 ...
随机推荐
- ios navigationController代码创建
1.新建类文件FirstViewController,subClass of:UIViewController 2.新建类文件MYNavigationController,subClass of:UI ...
- E - 小晴天老师系列——我有一个数列!
E - 小晴天老师系列——我有一个数列! Time Limit: 20000/10000MS (Java/Others) Memory Limit: 128000/64000KB (Java/O ...
- submit提交表单后,不刷新当前页面
<form method="get" target="test" action="a.html"> <input type ...
- nginx(ubuntu)设置别名访问目录
1 2 3 4 5 6 7 8 9 10 11 12 13 location /phpmyadmin/ { alias /data/phpmyadmin/; index index.html in ...
- hdu_5800_To My Girlfriend(变种背包)
题目链接:hdu_5800_To My Girlfriend 题意: 给你n和物品和一个重量m,让你求 题解: To My Girlfriend 令dp[i][j][s1][s2]表示前i个物品填了j ...
- hdu_5695_Gym Class(拓扑排序)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5695 题意:中文题,不解释 题解:逆向拓扑字典序就行 #include<cstdio> # ...
- 最近客户的apache+php环境运行很慢解决
描述:[Wed Jul 24 15:49:11 2013] [warn] (OS 64)指定的网络名不再可用. : winnt_accept: Asynchronous AcceptEx faile ...
- WEBROOT根目录 <%=request.getContextPath()%>
WEBROOT根目录 <%=request.getContextPath()%> == ${pageContext.request.contextPath}
- wifi的UI控制。打不开UI
部分主要是您要清楚WiFi作为什么功能,即WiFi是仅仅作为station功能,还是要开启p2p功能,当WiFi作为station功能时候开启的是wpa_supplicant服务,当WiFi作为p2p ...
- kill -0
http://unix.stackexchange.com/questions/169898/what-does-kill-0-do 检查有没有权限杀他