findFragmentById always returns null

前端 未结 9 614
时光说笑
时光说笑 2020-12-01 17:31

I\'m defining an ID for my fragment in the xml layout:




        
9条回答
  •  悲&欢浪女
    2020-12-01 18:24

    FragmentB fragmentB = 
    (FragmentB) getSupportFragmentManager().findFragmentById(R.id.containerb);
    
    if(fragmentB != null)
    {
       fragmentB.showuserResponse(msg);
    }
    

    Use container id as fragment id. And then check for null reference.

提交回复
热议问题