2015年7月10日 星期五

Avoiding fragment duplicates

if (mainview != null) {
    ViewGroup parent = (ViewGroup) mainview.getParent();    if (parent != null)
        parent.removeView(mainview);}
try {
    mainview = inflater.inflate(R.layout.fragment_user_group, container, false);} catch (InflateException e) {
/* map is already there, just return view as it is */}

http://stackoverflow.com/questions/11520761/avoiding-fragment-duplicates-app-crushes-due-to-the-id-property-of-the-fragment