How do I get the currently displayed fragment?

前端 未结 30 2111
青春惊慌失措
青春惊慌失措 2020-11-22 11:21

I am playing with fragments in Android.

I know I can change a fragment by using the following code:

FragmentManager fragMgr = getSupportFragmentManag         


        
30条回答
  •  [愿得一人]
    2020-11-22 11:27

    Well, this question got lots of views and attention but still did not contained the easiest solution from my end - to use getFragments().

                List fragments = getSupportFragmentManager().getFragments();
                mCurrentFragment = fragments.get(fragments.size() - 1);
    

提交回复
热议问题