I have a layout with two Fragments in it. The second is loaded dynamically.
Fragment fg = EmptyRightFrag.newInstance(); getFragmentManager().beginTransaction().add(R.id.right_frag, fg) .commit();
Then this second frame replaces another "fragment".
Fragment fg = MyClass.newInstance(); getFragmentManager().beginTransaction().replace(R.id.right_frag, fg) .commit();
Finally, I need to initialize the second Fragment by calling:
MyClass field = ((MyClass)getFragmentManager().findFragmentById(R.id.right_frag));
But here I get a java.lang.ClassCastException indicating EmptyRightFrag cannot be sent to MyClass .
source share