android - 没有 onCreateView 的片段
问题描述
最近我看到一些关于直接从 Fragment() 扩展片段布局的文章
class ExampleFragment: Fragment(R.layout.example_fragment)
这是否仅代表不包含任何数据和交互的片段,我们何时应该使用此方法
解决方案
这是在androidx.fragment 版本 1.1.0中添加的:
Fragment LayoutId 构造函数:Fragment 的子类现在可以选择调用 Fragment 上的构造函数,该构造函数采用 R.layout ID,指示应用于此 Fragment 的布局,以替代覆盖 onCreateView()。可以在 onViewCreated() 中配置膨胀的布局。
所以从本质上讲,它是覆盖的简写,onCreateView()
它只是膨胀布局并返回它,并鼓励一种在onViewCreated()
而不是onCreateView()
.
推荐阅读
- azure - 获取 Powershell 错误无法在 UpdateAzureRm-Vmss 上引用来自不同虚拟网络的子网
- reactjs - 如何从 HOC 更改 React-Bootstrap-Typeahead 的选定值
- javascript - NodeJs json发布请求BODY未被解析
- html - CSS 悬停过渡在我的网站上不起作用
- c# - 如何在不使用 goto 的情况下返回代码中的特定点?
- python - 移位以获得 128 位产品
- laravel - Laravel - 是否有任何刀片指令来检查变量是否存在并设置为特定值?
- design-patterns - 用点 lua 分割字符串
- java - 使用多线程系统监视 Zookeeper 上的多个节点
- mongodb-query - 如何在 mongoDB 的 $in 运算符中嵌套 $type