Click here to Skip to main content
14,364,399 members
Rate this:
Please Sign up or sign in to vote.
See more:
first code

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_a, container, false);
    listView = view.findViewById(;
    return view;

second code

    public void onActivityCreated(@Nullable Bundle savedInstanceState) {

         listView = getActivity().findViewById(;

* some people say the second one get the views from activity, but i used it to get views inside fragment(that didn't exists in activity) and it worked fine, so what is the difference ?

What I have tried:

there was nothing i could do !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100