【问题标题】:pass data to statically included fragment from fragment activity将数据从片段活动传递到静态包含的片段
【发布时间】:2014-12-04 11:43:23
【问题描述】:

我在我的 xml 布局中定义了一个片段,我想从我的片段活动将数据传递给它。那可能吗 ?我不想在运行时包含片段,因为我不打算在活动期间更改片段。 这是我的 xml

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <fragment
        android:id="@+id/profileFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        class="com.fragments.MyProfileFragment" >
    </fragment>

    <fragment
        android:id="@+id/hoppiesFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        class="com.fragments.HoppiesFragment" >
    </fragment>
</LinearLayout>

【问题讨论】:

  • 您能接受答案吗?
  • 我已接受您的回答。谢谢:)

标签: android android-fragments static fragment


【解决方案1】:

使用FragmentManager#findFragmentById 方法获取片段并将数据传递给它的一些公共方法。

【讨论】:

  • 非常感谢您的快速回复。 :)
  • 我很高兴能帮上忙。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多