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

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


second code

  @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);


         listView = getActivity().findViewById(R.id.listview);
}


* 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 !
Posted

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