How to refresh fragment by clicking on button

2.6k Views Asked by At

I want to refresh my fragment by clicking on its button. How to do it? I try to do it like this but old version of fragment appears on the top of the screen (picture is attached):

binding.checkAnswersButton.setOnClickListener {
           requireFragmentManager().beginTransaction().apply {
                replace(R.id.quizFragment, QuizFragment())
                    .commit()
           }
        }
1

There are 1 best solutions below

0
On

This will refresh the fragment :

    val ft = parentFragmentManager.beginTransaction()
    ft.detach(this).attach(this).commit()