【问题标题】:Getting the fragment from the current activity从当前活动中获取片段
【发布时间】:2015-10-30 22:25:45
【问题描述】:

大家好,我有片段

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.recordings, container, false);
}

这是我的布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recordinglayout">

如果不将它添加到我的活动中,我将如何获得这个片段对象?或者添加一些东西,例如从活动类到片段布局的按钮?

【问题讨论】:

    标签: android android-layout android-fragments android-activity


    【解决方案1】:

    Activity 不能引用尚未以某种方式实例化的片段。您可以通过 xml 中的片段标记来实例化片段,或者在 Java 中以编程方式创建片段。

    我建议您仔细查看creating (and referencing) fragments 上的文档:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-15
      • 1970-01-01
      • 2011-05-28
      相关资源
      最近更新 更多