Error inflating class fragment - duplicate id/illegalargumentexception?

后端 未结 7 901
梦毁少年i
梦毁少年i 2020-12-02 17:05

I\'m trying make an app that I\'m building take a search term from the main activity, return results, and then have the results be clickable such that a detail could be view

7条回答
  •  遥遥无期
    2020-12-02 17:58

    I had the same problem with fragment called twice and on the second time it crashed. Solution is to implement the remove statement in onDetach method:

        @override
    public void onDetach(){
    super.onDetach();
    FragmentManager fm = getFragmentManager()
    
    Fragment xmlFragment = fm.findFragmentById(R.id.yourfragmentid);
    if(xmlFragment != null){
        fm.beginTransaction().remove(xmlFragment).commit();
        }
    }
    

提交回复
热议问题