Create home screen Part 4 Uniquely adding fragment to fragment manager - Android Kotlin Tutorial

Опубликовано: 14 Январь 2018
на канале: Let's Finish this APP - Kotlin and Swift Tutorials
500
4

In this video we will learn how to add single fragment to fragment manager and if fragment is already added than our task is to show selected fragment and hide other fragment.

1) Use of fragment manager and Fragment transaction.

2) Use of show/hide function of fragment in Kotlin.

3) Perform a full transaction i.e either show or hide than commit.

4) Check if fragment is available in Fragment manager or not with the help of function isFragmentAlreadyAdded()

5) If fragment is already available in fragment manager than we show selected fragment with the help of showFragment() function.

6) Use for loop in Kotlin to traverse each fragment in fragment manager list.

7) Use of break-point, debugger and evaluate expression to check fragment manager list only contain unique fragment.

8) Final check application in emulator(Android O).

9) At the end we will notice that only single fragment saved in fragment manager list and we have successfully used show/hide function of fragment.