How to set a Fragment tag by code?

前端 未结 8 2367
我寻月下人不归
我寻月下人不归 2020-12-01 02:26

I haven\'t found something like setTag(String tagName) method in the Fragment class. The only way to set a Fragment tag that I have fo

8条回答
  •  离开以前
    2020-12-01 02:53

    You can set tag to fragment in this way:

    Fragment fragmentA = new FragmentA();
    getFragmentManager().beginTransaction()
        .replace(R.id.MainFrameLayout,fragmentA,"YOUR_TARGET_FRAGMENT_TAG")
        .addToBackStack("YOUR_SOURCE_FRAGMENT_TAG").commit(); 
    

提交回复
热议问题