Fragment 之间传值
来源:互联网 发布:赌博网站源码 编辑:程序博客网 时间:2024/06/05 02:57
MainActivity
//获取FragmentManager管理者
FragmentManager fragmentManager = getFragmentManager();//开启事务
FragmentTransaction fTransaction = fragmentManager.beginTransaction();
fTransaction.replace(R.id.ll1, new Fragment1(),"f1");fTransaction.replace(R.id.ll2, new Fragment2(),"f2");
fTransaction.commit();
Fragment1
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment1, null);
Toast.makeText(getActivity(), "dfsfsfsgfdgdf", 1).show();
Fragment2 fragment2 =(Fragment2)getActivity().getFragmentManager().findFragmentByTag("f2");
fragment2.setText("haahha");
return view;
}
Fragment2
private TextView tView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment2, null);
tView = (TextView) view.findViewById(R.id.tv);
return view;
}
// 修改textview值的方法
public void setText(String content) {
tView.setText(content);
}
- Fragment之间传值
- Fragment之间传值
- Fragment之间传值
- Fragment 之间传值
- Fragment 之间的传值
- activity嵌套fragment,fragment内嵌fragment之间传值切换fragment
- Activity和Fragment之间的传值
- Fragment与Activity之间传值
- Android fragment 之间传值的方法
- android中fragment之间传值
- Activity与Fragment之间的传值
- Fragment之间传值的方法
- DialogFragment与Fragment之间互相传值
- Fragment之间传值CallBack(Fragment01)
- Fragment之间传值CallBack(Fragment02)
- Fragment之间传值CallBack(MainActivity)
- Activity与Fragment之间的传值
- Fragment与Activity之间传值
- Php学习之内存泄漏问题详解
- 折线平行线的计算方法
- Spring MVC集成 Log4j
- fatal error LNK1561:必须定义入口点 问题的解决
- 简单的旋转,放大,缩小 (HTML5)
- Fragment 之间传值
- 插入排序与优化笔记
- 人类的下一代计算平台——科技大发展前景下的新思考
- 无人零售场景、技术全解读:伪需求or真风口?
- 说明:最新"谷歌AI智商不超过6岁"研究来自中国科学院而非美国康内尔大学
- 源码资本张宏江:只有算法和技术,那你一定挣不到钱
- AI技术的天花板:图灵机无法建立“自我”意识的概念
- imageloader工具类
- Kubernetes的service mesh——第二部分:以DaemonSet方式运行linkerd