How to set a Tag to a Fragment in Android

核能气质少年 提交于 2019-12-05 01:12:55

You can set a Tag during fragment transaction.

For example if it's a replace transaction you could do it like so:

FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
        .replace(R.id.fragment_container, mFragment, TAG)
        .commit();

If the Fragment you're using is not from Support Library, use getFragmentManager() instead of getSupportFragmentManager().

Olkunmustafa

I used that feature to provide between Dialog box and Fragment. When a alteration is made in Dialogbox, App can easily update Fragment UI

MyFragment.

DialogFragment dialog = LastCycleDate.newInstance( last_period_start );
        dialog.setTargetFragment( this, 0 );
        dialog.show( getActivity().getSupportFragmentManager(), "showLastCycleDate" );

MyDailogBox.java

Fragment targetFragment; = getTargetFragment();
if( targetFragment instanceof IntroParentFragment ){
            IntroParentFragment introParentFragment = ( IntroParentFragment ) targetFragment;
            introParentFragment.mutualMethods.setLastCycleStartDay( start_date );
        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!