apomytkina
apomytkina

Reputation: 19

How to refresh fragment by clicking on button

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()
           }
        }

Upvotes: 0

Views: 3165

Answers (1)

A Sarshar
A Sarshar

Reputation: 294

This will refresh the fragment :

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

Upvotes: 0

Related Questions