Call fragment events from activity

后端 未结 2 732
走了就别回头了
走了就别回头了 2020-12-15 11:38

So, I got the event in my fragment to pass to the activity, so how do I make it so the activity in turns, notifies fragment B to do something. I want to fragment B to popula

2条回答
  •  伪装坚强ぢ
    2020-12-15 12:15

    One way to do it would be like this in your activity:

    FragmentB fragmentB = (FragmentB)getFragmentManager().findFragmentById(R.id.fragmentBId);
    fragmentB.performSomeTask();
    

    This is of course assuming that you have a publicly accessibly method in FragmentB called performSomeTask();

    Hope that helps!

提交回复
热议问题