Refresh fragment when change between tabs

前端 未结 5 2178
难免孤独
难免孤独 2021-01-04 05:54

App open on first fragment and there is 2 tabs i want to refresh second fragment when i move to it but i don\'t want to refresh first fragment

MainActivity

5条回答
  •  暖寄归人
    2021-01-04 06:00

    Inside Your fragment class use the below code:

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser) {
            getFragmentManager().beginTransaction().detach(this).attach(this).commit();
        }
    }
    

提交回复
热议问题