Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – Reload a Fragment

Posted on November 11, 2022 By

Solution 1 :

just run this

getActivity().getSupportFragmentManager().beginTransaction().detach(this).attach(this).commit();

Problem :

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.

Comments

Comment posted by iCantC

just out of curiosity, why you want to reload a

Comment posted by Beatles BOB

I add some db data to firebase to an Mpandroidchart, and it doesn’t reload when data change

Comment posted by stackoverflow.com/questions/47303952/…

can you please check this link,

Comment posted by Beatles BOB

For me nothing happen 🙁

Comment posted by Beatles BOB

So I do like getActivity().getSupportFragmentManager().beginTransaction().detach(ProfilFragment.this).attach(ProfilFragment.this).commit(); but I receive Cannot detach Fragment attached to a different FragmentManager. Fragment ProfilFragment{ab662d} (22d9d467-dcfc-4dbc-8b00-fe827083f6a0) id=0x7f0900f6} is already attached to a FragmentManager.

Comment posted by Amit pandey

dont use ProfilFragment.this just use this

READ  [FIXED] android - ReferenceError: Can't find variable: Intl when try react-calendar
Powered by Inline Related Posts
Android Tags:android, android-fragments, reload

Post navigation

Previous Post: [FIXED] Xamarin.forms – Trouble behaviour between ListView & keyboard
Next Post: [FIXED] android – two elements in linear layout are packed to center instead of to the sides

Related Posts

[FIXED] java – How to share data between fragments and activities in android Android
[FIXED] java – How to install appAuth in android studio Android
[FIXED] java – How to create a HashMap that would have String as key and the value would be another HashMap from one list of custom object? Android
[FIXED] How to rotate image in 25-degree increments? Android animation Android
[FIXED] java – How do I do a BaseActivity or something similar so that I only have to do an Internet Connection BroadcastReceiver once? Android
[FIXED] java – Android fragment navigation without button click Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can VPN be traced by police?
  • Where were Kaiser-Frazer cars built?
  • How do you make gold rose gold paint?
  • What are the newest type of dentures?
  • Can you wear joggers as dress pants?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme