# FragmentTransactionKt

Added in 1.9.1

*** ** * ** ***


```
public final class FragmentTransactionKt
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` | `<F extends https://developer.android.com/reference/androidx/fragment/app/Fragment> https://developer.android.com/reference/androidx/fragment/app/FragmentTransactionKt#(androidx.fragment.app.FragmentTransaction).add(kotlin.String,android.os.Bundle)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html tag, https://developer.android.com/reference/android/os/Bundle.html args )` Add a fragment to the associated `https://developer.android.com/reference/androidx/fragment/app/FragmentManager` without adding the Fragment to any container view. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` | `<F extends https://developer.android.com/reference/androidx/fragment/app/Fragment> https://developer.android.com/reference/androidx/fragment/app/FragmentTransactionKt#(androidx.fragment.app.FragmentTransaction).add(kotlin.Int,kotlin.String,android.os.Bundle)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction receiver, @https://developer.android.com/reference/androidx/annotation/IdRes int containerViewId, https://developer.android.com/reference/java/lang/String.html tag, https://developer.android.com/reference/android/os/Bundle.html args )` Add a fragment to the associated `https://developer.android.com/reference/androidx/fragment/app/FragmentManager`, inflating the Fragment's view into the container view specified by `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentTransaction).add(kotlin.Int,kotlin.String,android.os.Bundle)`, to later retrieve via `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#findFragmentById(int)`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` | `<F extends https://developer.android.com/reference/androidx/fragment/app/Fragment> https://developer.android.com/reference/androidx/fragment/app/FragmentTransactionKt#(androidx.fragment.app.FragmentTransaction).replace(kotlin.Int,kotlin.String,android.os.Bundle)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction receiver, @https://developer.android.com/reference/androidx/annotation/IdRes int containerViewId, https://developer.android.com/reference/java/lang/String.html tag, https://developer.android.com/reference/android/os/Bundle.html args )` Replace an existing fragment that was added to a container. |

## Public methods

### add

Artifact: [androidx.fragment:fragment](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/app/FragmentTransaction.kt+function:add)

```
public static final @NonNull FragmentTransaction <F extends Fragment> add(
    @NonNull FragmentTransaction receiver,
    @NonNull String tag,
    Bundle args
)
```

Add a fragment to the associated `https://developer.android.com/reference/androidx/fragment/app/FragmentManager` without adding the Fragment to any container view.

The new fragment to be added will be created via the `https://developer.android.com/reference/androidx/fragment/app/FragmentFactory` of the `https://developer.android.com/reference/androidx/fragment/app/FragmentManager`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html tag` | Tag name for the fragment, to later retrieve the fragment with `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#findFragmentByTag(java.lang.String)`. |
| `https://developer.android.com/reference/android/os/Bundle.html args` | Optional arguments to be set on the fragment. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` | Returns the same `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` instance. |

### add

Artifact: [androidx.fragment:fragment](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/app/FragmentTransaction.kt+function:add)

```
public static final @NonNull FragmentTransaction <F extends Fragment> add(
    @NonNull FragmentTransaction receiver,
    @IdRes int containerViewId,
    String tag,
    Bundle args
)
```

Add a fragment to the associated `https://developer.android.com/reference/androidx/fragment/app/FragmentManager`, inflating the Fragment's view into the container view specified by `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentTransaction).add(kotlin.Int,kotlin.String,android.os.Bundle)`, to later retrieve via `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#findFragmentById(int)`.

The new fragment to be added will be created via the `https://developer.android.com/reference/androidx/fragment/app/FragmentFactory` of the `https://developer.android.com/reference/androidx/fragment/app/FragmentManager`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IdRes int containerViewId` | Identifier of the container this fragment is to be placed in. |
| `https://developer.android.com/reference/java/lang/String.html tag` | Optional tag name for the fragment, to later retrieve the fragment with `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#findFragmentByTag(java.lang.String)`. |
| `https://developer.android.com/reference/android/os/Bundle.html args` | Optional arguments to be set on the fragment. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` | Returns the same `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` instance. |

### replace

Artifact: [androidx.fragment:fragment](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/app/FragmentTransaction.kt+function:replace)

```
public static final @NonNull FragmentTransaction <F extends Fragment> replace(
    @NonNull FragmentTransaction receiver,
    @IdRes int containerViewId,
    String tag,
    Bundle args
)
```

Replace an existing fragment that was added to a container. This is essentially the same as calling `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction#remove(androidx.fragment.app.Fragment)` for all currently added fragments that were added with the same `containerViewId` and then `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction#add(java.lang.Class<? extends androidx.fragment.app.Fragment>,android.os.Bundle,java.lang.String)` with the same arguments given here.

The new fragment to place in the container will be created via the `https://developer.android.com/reference/androidx/fragment/app/FragmentFactory` of the `https://developer.android.com/reference/androidx/fragment/app/FragmentManager`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IdRes int containerViewId` | Identifier of the container whose fragment(s) are to be replaced. |
| `https://developer.android.com/reference/java/lang/String.html tag` | Optional tag name for the fragment, to later retrieve the fragment with `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#findFragmentByTag(java.lang.String)`. |
| `https://developer.android.com/reference/android/os/Bundle.html args` | Optional arguments to be set on the fragment. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` | Returns the same `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` instance. |