Reload a Fragment
NickName:Beatles BOB Ask DateTime:2020-02-27T20:34:58

Reload a Fragment

everyone, my issue is :

I'm in ProfilFragment, that was generated with the Menu Drawer it extends Fragment, and I can't change this (it broke some other part). When I click on a button I want to refresh my current Fragment

// Reload current fragment
                        Fragment frg = null;
                        frg = getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_profil);
                        FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
                        ft.detach(frg);
                        ft.attach(frg);
                        ft.commit();

I found this on other StackOverflow issues but it didn't work for me. frg = getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_profil); Always return null

Even if in my mobile_navigation.xml I have

<fragment
    android:id="@+id/nav_profil"
    android:name="com.example.pierregignoux.ui.profil.ProfilFragment"
    tools:layout="@layout/fragment_profil" />

Any help would be great, Thanks a lot.

Copyright Notice:Content Author:「Beatles BOB」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60433365/reload-a-fragment

More about “Reload a Fragment” related questions

Reload Fragment

I am just curious, as I have set up Fragment tabs in a FragmentActivity, how to reload a fragment either from the FragmentActivity, or from the Fragment itself, to just purge and reload that tab. I

Show Detail

Refresh Fragment at reload

In an android application I'm loading data from a Db into a TableView inside a Fragment. But when I reload the Fragment it displays the previous data. Can I repopulate the Fragment with current data

Show Detail

Reload a Fragment

everyone, my issue is : I'm in ProfilFragment, that was generated with the Menu Drawer it extends Fragment, and I can't change this (it broke some other part). When I click on a button I want to

Show Detail

Reload Fragment after popBackStack

I need reload fragment after this process Go from Fragment A to Fragment B and go from Fragment B to Fragment C, then do the registration process, and after the registration is correct, popBackStack

Show Detail

Fragment crashing on reload

My Problem is, on the second reload my fragment is crashing with a NullPointerException. The exception leads to FragmentTransaction ft = getFragmentManager().beginTransaction(); LogCat: java.lang.

Show Detail

How to reload Fragment?

Here is my situation : I'm retrieving data from a database in a fragment and the result is asynchronous. So I want to reload the view after I get result from database. I've tried many ways with "

Show Detail

Android - Reload Fragment into a ViewPager

I'm building an App which extracts data from a SQLite local database. I have an Activity, in which I use a ViewPager; in this ViewPager, there are 12 swipable Fragments. I'd like to implement a "...

Show Detail

how to reload a fragment oncreatview on activity finish

I have a fragment and there is a list of items.I have an async task in the fragments oncreateview which loads the items. Upon the click of items I am launching an activity. After I perform some ac...

Show Detail

refresh fragment at reload or after rotating

I wrote the following code fragment regenerate when the screen is rotated. the fragment setArguments is a "java.lang.IllegalStateException" error occurs. What better way is there to do? Referenc...

Show Detail

Reset/reload fragment container

How can I reset or reload a fragment container, to make it empty. I have a master detail view and I want to reset the detail container to empty on a menu item click.This works in some cases and doe...

Show Detail