android - 在 fragment 中刷新 fragment

标签 android android-fragments swiperefreshlayout

如何在父 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/

相关文章:

android - FragmentPagerAdapter、 fragment 、support.v4 和 support.v13

android - 使用emptyView和ListView时的SwipeRefreshLayout问题

android - 异常调度输入事件和 SwipeRefreshLayout 下拉空指针异常

Android:在真实设备上记录或异常堆栈跟踪

java - libgdx 绘制汉字

android - 前台服务示例

java - 如何动态地使这个子 Fragment 的 TextView 可见/不可见?

android - 如何使用带有下拉刷新和滑动删除的Listview

Android:如何使用 GSON 库解析 JSON 文件?

java - Android ListView : changing dataset and calling notifyDataSetChanged inside of getView