Android Fragment no view found for ID?

前端 未结 30 2373
逝去的感伤
逝去的感伤 2020-11-22 05:33

I have a fragment I am trying to add into a view.

FragmentManager fragMgr=getSupportFragmentManager();
feed_parser_activity content = (feed_parser_activity)f         


        
30条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 05:51

    I know this has already been answered for one scenario, but my problem was slightly different and I thought I'd share in case anybody else is in my shoes.

    I was making a transaction within onCreate(), but at this point the view tree has not been inflated so you get this same error. Putting the transaction code in onResume() made everything run fine.

    So just make sure your transaction code runs after the view tree has been inflated!

提交回复
热议问题