-4

I have a fragment and I need to completely refresh/reinstantiate it. By refreshing I mean recreating fragment. I have tried using FragmentManager with detach() method but it didn't help. All EditText children of that fragment still have their values entered even though the fragment was refreshed

Is there any way to achieve this result?

awave
  • 152
  • 4
  • 13
  • 3
    Possible duplicate of [refresh fragment at reload](http://stackoverflow.com/questions/20702333/refresh-fragment-at-reload) – sijeesh Jun 22 '16 at 09:57

3 Answers3

0

if there are only edit texts , create a method that sets all edit texts to empty string that is et(edit_text object),

et.setText("");    //edit text will be reset  
Janki Gadhiya
  • 4,492
  • 2
  • 29
  • 59
0

Put the following code inside the fragment which need to be refreshed.

FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.detach(this).attach(this).commit();

Use fragment manger according to your code (if it is an old version then this will be supportFragmentManager)

Sudhi
  • 403
  • 4
  • 8
0

Put and call this method to your fragment

private void reloadFragment(){
    Fragment frg = getActivity().getSupportFragmentManager().findFragmentByTag(ReceiptFragment.TAG);
    final FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
    ft.detach(frg);
    ft.attach(frg);
    ft.commit();
}
Laurence Pardz
  • 292
  • 3
  • 8