How can I recreate a fragment?

I’m using a widget called SwipeRefreshLayout, to refresh my fragment when someone pushes the view.

To recreate the activity I have to use:

SwipeRefreshLayout mSwipeRefreshLayout;

public static LobbyFragment newInstance() {
    return new LobbyFragment();

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_lobby, container, false);

    receiver = new MySQLReceiver();

    rlLoading = (RelativeLayout) view.findViewById(;
    gvLobby = (GridView) view.findViewById(;


    mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(;
    mSwipeRefreshLayout.setColorSchemeResources(R.color.pDarkGreen, R.color.pDarskSlowGreen, R.color.pLightGreen, R.color.pFullLightGreen);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        public void onRefresh() {



    return view;


But I don’t want to recreate the full activity that contains the view pager, I would like to recreate the fragment. How can I do that?


You can use :

                .replace(, LobbyFragment.newInstance()).commit();

To recreate your fragment

Note:getSupportFragmentManager() is if you are using support fragment and AppCompatActivity , if you are using framework fragment class you need to use getFragmentManager()