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
fragment.getView().invalidate();
which didn't seem to do the work. I also tried
fragment.getView().requestLayout();
which didn't work either.
On another activity, I have a ListFragment which needs to do the same thing. I tried
listfragment.getListView().invalidate();
which did the trick, refreshing my list view and redrawing all the items inside it.
I don't understand why one works but not the other.
I have also seen people recommending initiating a fragment transaction and replacing the current fragment with a new one, and it has kept me wondering
Why should I create a whole new fragment and replace my current fragment when all I need is to refresh the text on the views that my fragment contains.
Fragment transaction method will prevent me from defining my fragment in the layout xml of my activity and I will have to programatically insert the fragment at the right position.
Is there any simple approach to this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…