Package icyllis.modernui.fragment
Class FragmentFactory
java.lang.Object
icyllis.modernui.fragment.FragmentFactory
Interface used to control the instantiation of
Fragment
instances.
Implementations can be registered with a FragmentManager
via
FragmentManager.setFragmentFactory(FragmentFactory)
.- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioninstantiate
(Class<? extends Fragment> clazz) Create a new instance of a Fragment with the given class name.instantiate
(ClassLoader classLoader, String className) Create a new instance of a Fragment with the given class name.loadFragmentClass
(ClassLoader classLoader, String className) Parse a Fragment Class from the given class name.
-
Constructor Details
-
FragmentFactory
public FragmentFactory()
-
-
Method Details
-
loadFragmentClass
@Nonnull public static Class<? extends Fragment> loadFragmentClass(@Nonnull ClassLoader classLoader, @Nonnull String className) Parse a Fragment Class from the given class name. The resulting Class is kept in a global cache, bypassing theClass.forName(String)
calls when passed the same class name again.- Parameters:
classLoader
- The classloader to use for loading the ClassclassName
- The class name of the fragment to parse.- Returns:
- Returns the parsed Fragment Class
- Throws:
RuntimeException
- If there is a failure in parsing the given fragment class. This is a runtime exception; it is not normally expected to happen.
-
instantiate
Create a new instance of a Fragment with the given class name. This usesloadFragmentClass(ClassLoader, String)
and theninstantiate(Class)
.- Parameters:
classLoader
- The classloader to use for instantiationclassName
- The class name of the fragment to instantiate.- Returns:
- Returns a new fragment instance.
- Throws:
RuntimeException
- If there is a failure in instantiating the given fragment class. This is a runtime exception; it is not normally expected to happen.
-
instantiate
Create a new instance of a Fragment with the given class name. This the empty constructor of the resulting Class by default.- Parameters:
clazz
- The loaded class of the fragment to instantiate.- Returns:
- Returns a new fragment instance.
- Throws:
RuntimeException
- If there is a failure in instantiating the given fragment class. This is a runtime exception; it is not normally expected to happen.
-