Android Fragment no view found for ID?

前端 未结 30 2326
逝去的感伤
逝去的感伤 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:54

    In my case. I have an Activity with serveral Fragments some time I need to recreate Fragments when

  • language is change
  • fragment layout some need some not need or content change need to recreate
  • other changes
  • I clear all Fragments and set all to null in activity but Fragment already create itself, while it host activty is bean set null, so before call Fragment view check it null

    for example

    Activity{
        fragment
        recreate{
           fragment = null then new instance
        }
    
    }
    
    Fragment{
        if((activity).fragment != null) {
           findViewById()
        }
    
    }
    

提交回复
热议问题