What is the point of using view.getRootView().findViewById() inside of onViewCreated in fragment?

Viewed 64

I am watching a tutorial in which the instructor uses

test = view.getRootView().findViewById(R.id.test);

inside of onViewCreated() in the fragment.

So something like this:

 @Override
    public void onViewCreated(@NonNull @NotNull View view, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        //test is just a TextView for testing the application, will remove it later
        test = view.getRootView().findViewById(R.id.test);
    }

Is there any point of using view.getRootView().findViewById() opposed to just using view.findViewById()? I'm a little confused on the purpose of getRootView() here as the instructor uses.

Thank you!

0 Answers
Related