gpt4 book ai didi

android - 在 fragment 中刷新 fragment

转载 作者:行者123 更新时间:2023-11-29 14:45:40 29 4
gpt4 key购买 nike

如何在父 fragment 中刷新我的 fragment (图表 fragment )?
我试着像 this 那样做, 但它不起作用。

Java(刷新方法):

Fragment fragment = getChildFragmentManager().findFragmentById(R.id.statistic_order_fragment);
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.detach(fragment);
fragmentTransaction.attach(fragment);
fragmentTransaction.commit();

XML:

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ScrollView xmlns:card_view="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<fragment
android:id="@+id/statistic_order_fragment"
android:tag="ORDER"
android:name="com.readyscript.dk.storemanagement.Statistic.StatisticOrderFragment"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_gravity="center_horizontal"
card_view:layout="@layout/fragment_statistic_order" />

<fragment
android:id="@+id/statistic_sum_fragment"
android:tag="SUM"
android:name="com.readyscript.dk.storemanagement.Statistic.StatisticSumFragment"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_gravity="center_horizontal"
card_view:layout="@layout/fragment_statistic_sum" />

<fragment
android:id="@+id/statistic_check_fragment"
android:tag="CHECK"
android:name="com.readyscript.dk.storemanagement.Statistic.StatisticCheckFragment"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_gravity="center_horizontal"
card_view:layout="@layout/fragment_statistic_check" />

</LinearLayout>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>

当我使用 SwipeRefreshLayout 时,我需要在不重启父 Fragment 的情况下刷新所有 3 个 Fragment。

最佳答案

经过这么多编码...我得到了解决方案..

 getActivity().getSupportFragmentManager().beginTransaction().replace(**containerId**,
new **NameOfCurrentFragment**).commit();

关于android - 在 fragment 中刷新 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39453675/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com