Click here to Skip to main content
16,020,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900