Refresh or force redraw the fragment

后端 未结 8 1643
失恋的感觉
失恋的感觉 2020-11-30 02:10

I have a fragment that inflates an xml layout. My requirement is to update the text size on all my views inside my fragment when my Activity is resumed. I tried



        
8条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 02:42

    I do not think there is a method for that. The fragment rebuilds it's UI on onCreateView()... but that happens when the fragment is created or recreated.

    You'll have to implement your own updateUI method or where you will specify what elements and how they should update. It's rather a good practice, since you need to do that when the fragment is created anyway.

    However if this is not enough you could do something like replacing fragment with the same one forcing it to call onCreateView()

    FragmentTransaction tr = getFragmentManager().beginTransaction();
    tr.replace(R.id.your_fragment_container, yourFragmentInstance);
    tr.commit()
    

    NOTE

    To refresh ListView you need to call notifyDataSetChanged() on the ListView's adapter.

提交回复
热议问题