Refreshing a view inside a fragment

后端 未结 5 853
太阳男子
太阳男子 2020-12-23 22:20

I have searched the numerous questions that look like this one, but haven\'t found my answer in any of them.

I have an activity that has 3 tabs accessible through th

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-23 23:06

    I had the same issue. My solution was detach fragment and attach it again.

            FragmentManager fragmentManager = getSupportFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            Fragment f = getFragment(action);
            if(forceUpdate)
            {
                fragmentTransaction.detach(f);
                fragmentTransaction.attach(f);
            }
            fragmentTransaction.replace(R.id.mainFragment, f);
            fragmentTransaction.commit();
            currentAction = action;
    

提交回复
热议问题