public void onObjectUpdated() { Log.i(TAG, "Object " + m_id + " updated"); View rootView = getView(); if (rootView != null) { ViewSwitcher sw = (ViewSwitcher) getView().findViewById(R.id.switcher); if (m_child != null) { if (sw.getCurrentView().getId() != R.id.objectDisplayFragment) sw.showNext(); // Notify the child m_child.objectUpdated(m_object); return; } // Construct the child fragment ObjectFragment frag = null; if (m_object == null) { frag = new NullObjectFragment(); } else if ("person".equals(m_object.optString("objectType"))) { frag = new PersonObjectFragment(); } else { frag = new StandardObjectFragment(); } FragmentManager mgr = getChildFragmentManager(); m_child = ObjectFragment.prepare(frag, m_id, m_intId); mgr.beginTransaction().add(R.id.objectDisplayFragment, m_child).commit(); sw.showNext(); } else { // Nothing to do - our UI hasn't yet been created // We will update when we have a child } }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (savedInstanceState != null) { Class<ObjectFragment> childClass = (Class<ObjectFragment>) savedInstanceState.getSerializable("childClass"); if (childClass != null) { try { m_child = childClass.newInstance(); } catch (java.lang.InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } m_child = ObjectFragment.prepare(m_child, m_id, m_intId); m_child.setInitialSavedState((SavedState) savedInstanceState.getParcelable("child")); getChildFragmentManager() .beginTransaction() .add(R.id.objectDisplayFragment, m_child) .commit(); } } }