We have to use a companion
object to instantiate a fragment. Remember we have to use the newInstance()
method to initialize a fragment because we cannot use the parameterized constructor for fragments.
companion object {
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"
@JvmStatic
fun newInstance(param1: String, param2: String) =
Fragment().apply {
arguments = Bundle().apply {
putString(ARG_PARAM1, param1)
putString(ARG_PARAM2, param2)
}
}
}