unable to pass number into Fragment

Viewed 37

fragment run:

            val fragment = DescriptionFragment()
            val bundle = Bundle()
            bundle.putInt("position", position)
            fragment.setArguments(bundle)

            val activity=context.context as AppCompatActivity
            activity.supportFragmentManager
                .beginTransaction()
                .replace(R.id.framelayout, fragment)
                .commitNow()

teaching a number inside a fragment:

val position: Int = getArguments()?.getInt("position", 0) ?: 0

but it is not possible to pass a number, position is always 0

in details:

class DescriptionFragment : Fragment() {

...

    val position: Int = getArguments()?.getInt("position", 0) ?: 0

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

...
    }
0 Answers
Related