Refreshing a view inside a fragment

后端 未结 5 836
太阳男子
太阳男子 2020-12-23 22:20

I have searched the numerous questions that look like this one, but haven\'t found my answer in any of them.

I have an activity that has 3 tabs accessible through th

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-23 22:52

    I had a similar (although not identical) problem that I could solve in the following way:

    In the fragment I added

    public void invalidate() {
        myView.post(new Runnable() {
            @Override
            public void run() {
                myView.invalidate();
            }
        });
    }
    

    and I called this method from the activity when I wanted to refresh the view myView of the fragment. The use of post() ensures that the view is only invalidated when it is ready to be drawn.

提交回复
热议问题