android - 容器如何传递给 fragment ?

标签 android android-fragments

我正在尝试理解其他人的代码。他们正在使用 fragment (我不太清楚)。

我知道 fragment 以 onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState 开始......但我无法理解“容器”的设置位置。

我应该看哪里?

最佳答案

container 是由Android框架处理的,它通常指的是像FragmentTransaction的add(int containerViewId, Fragment fragment)这样的方法中通过id传递的View。或 replace(int containerViewId, Fragment fragment) .

例如,这是来自 Developer's Guide :

ExampleFragment fragment = new ExampleFragment();
fragmentTransaction.add(R.id.fragment_container, fragment);
fragmentTransaction.commit();

关于android - 容器如何传递给 fragment ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15482844/

相关文章:

android - 在 Fragment 中打开 Android Sqlite 数据库

android - 在 InstantApps 类中找不到 showInstallPrompt

android - 如何序列化 android.graphics.Path 的对象

android - 使用 DrawerLayout 时发生未知错误?

java - 从Dialog到MainActivity的访问方法

android - 单击菜单项后我的抽屉导航没有关闭?

android - 切换 fragment 时如何保持 subview 的状态?

android - 如何在android自定义搜索栏中设置工具提示文本?

javascript - 不明白如何在使用 PhoneGap 时将数据从 Android Activity 传递到 HTML UI

Android 多个WebView保存实例