androidx.fragment.app
Interfaces
BackStackEntry |
Representation of an entry on the fragment back stack, as created with |
OnBackStackChangedListener |
Interface to watch for changes to the back stack. |
FragmentOnAttachListener |
Listener for receiving a callback immediately following |
FragmentResultListener |
Listener for handling fragment results. |
FragmentResultOwner |
A class that manages passing data between fragments. |
Classes
DialogFragment |
Static library support version of the framework's |
Fragment |
Static library support version of the framework's |
FragmentActivity |
Base class for activities that want to use the support-based |
FragmentContainer |
Callbacks to a |
FragmentContainerView |
FragmentContainerView is a customized Layout designed specifically for Fragments. |
FragmentController |
Provides integration points with a |
FragmentFactory |
Interface used to control the instantiation of |
FragmentHostCallback |
Integration points with the Fragment host. |
FragmentManager |
Static library support version of the framework's |
FragmentManagerNonConfig |
FragmentManagerNonConfig stores the retained instance fragments across activity recreation events. |
FragmentPagerAdapter |
Implementation of |
FragmentStatePagerAdapter |
Implementation of |
FragmentTabHost |
Special TabHost that allows the use of |
FragmentTransaction |
Static library support version of the framework's |
ListFragment |
Static library support version of the framework's |
Annotations
FragmentStateManagerControl |
Extension functions summary
For android.view.View | |
F |
For Fragment | |
Lazy<VM> |
Fragment.activityViewModels(noinline factoryProducer: () -> ViewModelProvider.Factory = null) Returns a property delegate to access parent activity's ViewModel, if factoryProducer is specified then ViewModelProvider.Factory returned by it will be used to create ViewModel first time. |
Unit |
Fragment.clearFragmentResult(requestKey: String) Clears the stored result for the given requestKey. |
Unit |
Fragment.clearFragmentResultListener(requestKey: String) Clears the stored FragmentResultListener for the given requestKey. |
Lazy<VM> |
Fragment.createViewModelLazy(viewModelClass: KClass<VM>, storeProducer: () -> ViewModelStore, factoryProducer: () -> ViewModelProvider.Factory = null) Helper method for creation of ViewModelLazy, that resolves |
Unit |
Fragment.setFragmentResult(requestKey: String, result: Bundle) Sets the given result for the requestKey. |
Unit |
Fragment.setFragmentResultListener(requestKey: String, listener: (requestKey: String, bundle: Bundle) -> Unit) Sets the FragmentResultListener for a given requestKey. |
Lazy<VM> |
Fragment.viewModels(noinline ownerProducer: () -> ViewModelStoreOwner = { this }, noinline factoryProducer: () -> ViewModelProvider.Factory = null) Returns a property delegate to access ViewModel by default scoped to this Fragment: |
For FragmentTransaction | |
FragmentTransaction |
FragmentTransaction.add(@IdRes containerViewId: Int, tag: String? = null, args: Bundle? = null) Add a fragment to the associated FragmentManager, inflating the Fragment's view into the container view specified by containerViewId, to later retrieve via FragmentManager.findFragmentById. |
FragmentTransaction |
FragmentTransaction.add(tag: String, args: Bundle? = null) Add a fragment to the associated FragmentManager without adding the Fragment to any container view. |
FragmentTransaction |
FragmentTransaction.replace(@IdRes containerViewId: Int, tag: String? = null, args: Bundle? = null) Replace an existing fragment that was added to a container. |
For FragmentManager | |
Unit |
FragmentManager.commit(allowStateLoss: Boolean = false, body: FragmentTransaction.() -> Unit) Run body in a FragmentTransaction which is automatically committed if it completes without exception. |
Unit |
FragmentManager.commitNow(allowStateLoss: Boolean = false, body: FragmentTransaction.() -> Unit) Run body in a FragmentTransaction which is automatically committed if it completes without exception. |
Unit |
FragmentManager.transaction(now: Boolean = false, allowStateLoss: Boolean = false, body: FragmentTransaction.() -> Unit) Run body in a FragmentTransaction which is automatically committed if it completes without exception. |
Extension functions
activityViewModels
@MainThread inline fun <reified VM : ViewModel> Fragment.activityViewModels(noinline factoryProducer: () -> ViewModelProvider.Factory = null): Lazy<VM>
Returns a property delegate to access parent activity's ViewModel, if factoryProducer is specified then ViewModelProvider.Factory returned by it will be used to create ViewModel first time. Otherwise, the activity's androidx.activity.ComponentActivity.getDefaultViewModelProviderFactory will be used.
class MyFragment : Fragment() { val viewmodel: MyViewModel by activityViewModels() }
This property can be accessed only after this Fragment is attached i.e., after Fragment.onAttach, and access prior to that will result in IllegalArgumentException.
add
inline fun <reified F : Fragment> FragmentTransaction.add(
@IdRes containerViewId: Int,
tag: String? = null,
args: Bundle? = null
):