Get the view of a Fragment outside of OnCreateView() - View is null

283 Views Asked by At

Inside onCreateView i can instance View with the inflate, in this way:

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        // Inflate the layout for this fragment
        if(savedInstanceState == null) {
            v = inflater.inflate(R.layout.fragment_my_team, container, false);
            setUpRecyclerView(v);
        }

        return v;
    }

Now, if launch a second activity when return in the first activity, in this fragment, the View is null because onCreateView it's already called. I don't know a to instance the view.

Is there a solution of that?

1

There are 1 best solutions below

2
fraggjkee On

Get rid of the if(savedInstanceState == null) validation and create & return your view every time onCreateView is invoked.