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页面有重叠现象,让我十分不爽.研究了一天,终于明白其中的原理并加以解决.解决办法如下: 如果系统内存不 ...
随机推荐
- HDU 1372 Knight Moves(BFS)
题目链接 Problem Description A friend of you is doing research on the Traveling Knight Problem (TKP) whe ...
- 小心DLL链接静态库时的内存错误
本文转自http://www.bennychen.cn/2010/09/%E5%B0%8F%E5%BF%83dll%E9%93%BE%E6%8E%A5%E9%9D%99%E6%80%81%E5%BA% ...
- Openjudge-计算概论(A)-第二个重复出现的数
描述: 给定一个正整数数组(元素的值都大于零),输出数组中第二个重复出现的正整数,如果没有,则输出字符串"NOT EXIST". 输入第一行为整数m,表示有m组数据.其后每组数据分 ...
- onmousedown活用之鼠标拖动
这个布局蛮简单的就是一个div块,通过定位,固定位置 <html> <head> <meta charset="UTF-8"> <titl ...
- 【优先队列-求第Ki大的数】Black Box
Black Box Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8637 Accepted: 3542 Descrip ...
- ural 1353. Milliard Vasya's Function(dp)
1353. Milliard Vasya's Function Time limit: 1.0 second Memory limit: 64 MB Vasya is the beginning ma ...
- 杭电1002 Etaoin Shrdlu
Problem Description The relative frequency of characters in natural language texts is very important ...
- linux重新部署mysql和tomcat时乱码问题
mysql解决方法 vim /etc/my.cnf [client]default-character-set=utf8 [mysqld]default-storage-engine=INNODBch ...
- android activity中监听View测量完成的4种方式
在开发中经常碰到需要在activity初始化完成后获得控件大小的情况. 但是这个操作我们不能在oncreate.onresume等生命周期方法中调用,因为我们不知道何时view才能初始化完成 为此,特 ...
- ios 测试工程是否内存泄漏
转自http://www.cocoachina.com/ios/20141203/10519.html 虽然iOS 5.0版本之后加入了ARC机制,由于相互引用关系比较复杂时,内存泄露还是可能存在.所 ...