I'm building an android app in which I use one Activity from which I can load several fragments. So I start with the FragmentA, and from that I load Fragment B as follows:
FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
tx.replace(R.id.content_frame, detailsFragment).addToBackStack(null).commit();
This works fine. When I press the backbutton, it also goes back to FragmentA perfectly well. The problem is that when I click on the button to go to FragmentB again I get an InflateException (Duplicate id 0x7f08007a, tag null, or parent id 0x0 with another fragment for com.ourcomp.fragment.DetailsFragment
) on this line:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_details, null);
}
I think I need to check whether it was inflated already, but I don't really know how. Does anybody know how I can check wether the view was already inflated so that I can prevent this error?