Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation Architecture component- How to refresh a fragment?

I have a ListFragment that has a recyclerview and onClick on any items opens the DetailsFragment. The details fragment contains another recyclerview on the bottom that shows "MORE ITEMS". Now onClick on any of these items should open the DetailsFragment for that particular item. Basically the fragment needs to be refreshed.

In the past, I would just replace fragment using fragmentManager. How do I go about refreshing the fragment? How can I create an action that points to the same fragment?

like image 721
Sammys Avatar asked Jul 26 '18 23:07

Sammys


People also ask

How do I refresh a fragment from another fragment?

So when you click your Button , find the Fragment you want to refresh by its tag, and then call your refresh method.

How do you refresh a fragment on a resume?

The onResume() get called always before the fragment is displayed. Even when the fragment is created for the first time . So you can simply move your from onViewCreated() to onResume .

Are fragments reusable?

A Fragment represents a reusable portion of your app's UI. A fragment defines and manages its own layout, has its own lifecycle, and can handle its own input events. Fragments cannot live on their own--they must be hosted by an activity or another fragment.


1 Answers

Creating an action from DetailsFragment to DetailsFragment and navigating to this action worked as mentioned by Alex

like image 114
Sammys Avatar answered Oct 17 '22 03:10

Sammys