Fragment onViewCreated 的作用
发布日期:2021-06-30 08:02:16
浏览次数:4
分类:技术文章
本文共 1343 字,大约阅读时间需要 4 分钟。
onViewCreated 这个也是自己经常使用的到的,今天礼拜天在家复习知识点 这里记录一下
Fragment 是 3.0版本 API 11 的时候引入的,刚开始的时候并没有onViewCreated ,
它是在API 13的时候引入的 估计这个就是为啥Fragment 生命周期里面没有onViewCreated吧
但是onViewCreated 在Fragment 是有体现的
自己的测试如下
那我们使用呢如下
@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.order_food_fragment_layout, container, false); Log.e("=======onCreateView","onCreateView"); return view; } @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); Log.e("=========onViewCreated","onViewCreated"); textView = view.findViewById(R.id.food); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } }); }
我们使用的时候也很便 它返回fragment要显示的布局view ,这样我们在指定布局的时候就简单的多了 ,在findViewById前面添加一个view 即可
最后看下文档上面提到的
Called immediately after has returned, but before any saved state has been restored in to the view. This gives subclasses a chance to initialize themselves once they know their view hierarchy has been completely created. The fragment's view hierarchy is not however attached to its parent at this point.
转载地址:https://huxiaomu.blog.csdn.net/article/details/100187169 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月09日 19时43分48秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
oracle加密存储过程(函数、包)
2019-04-30
linux安装禅道
2019-04-30
glassfish服务器的安装和使用
2019-04-30
oracle数据库RMAN备份篇
2019-04-30
小程序调用系统照相机
2019-04-30
1.项目中高级编码之缓存get/set
2019-04-30
1.项目中高级编码之jdk8特性运用
2019-04-30
14.docker网络基本知识
2019-04-30
15.docker实战之redis集群
2019-04-30
16.Dockerfile 实战之发布springboot项目
2019-04-30
15.1docker部署单机redis
2019-04-30
17.docker实战之安装ES
2019-04-30
18.docker实战之idea添加docker插件
2019-04-30
java 高效工具库
2019-04-30
19.docker之dockerCompose基础
2019-04-30
20.docker之DockerCompose基础进阶
2019-04-30
1.全局异常处理
2019-04-30
3.mysql 索引基础知识
2019-04-30
线程、事件与QObject
2019-04-30
树莓派4不连接显示器开机的方法
2019-04-30