0

I have main activity like this:

MainActivity and ExampleFragment

I need to update my fragment when some one change something in spinner. I know i can use interfaces, and im using it in my application but in this case i cant do that. I searched some many topics in stackoverflow and there i found only this:

                        if (myFragment.getArguments() != null) {
                            myFragment.getArguments().putParcelable(Constants.USER,user);
                            myFragment.getArguments().putParcelable(Constants.PATIENT,pickedPatient);
                        }

I was trying detach and then attach my fragment to refresh, but data in bundle is not updated, and my fragment is just empty. I checked my logs and old data is still available.

Is there any solution for that problem? Or can I access my toolbar with spinner in my fragments and then update data in whole activity?

Some example with my another fragment here:

AnotherFragment

1 Answers1

0

Create new Fragment instance for the myFragment like

myFragment = new MyFragment();

And use .replace method to change the fragment.

Eren Utku
  • 1,731
  • 1
  • 18
  • 27
  • But i have to know which fragment i have to use. How create new instance when i have old fragment from: Fragment myFragment = getSupportFragmentManager().findFragmentById(R.id.content_frame); – Gnidus Totalus Apr 10 '18 at 11:20
  • You can create different fragments in java. So with that way you will know which fragment you are using and you can replace it by using replace method like this: https://stackoverflow.com/a/18940937/4376058 – Eren Utku Apr 10 '18 at 11:39
  • 1
    Ok thank you for your help, i just did sth like that: https://pastebin.com/FUyVG5rm – Gnidus Totalus Apr 10 '18 at 12:19