Create listview in fragment android

后端 未结 5 560
难免孤独
难免孤独 2020-12-05 07:24

As the title I want to create a listview with custom row in Fragment. My code below.

Fragment class

public class PhotosFragment extends Fragment{

pu         


        
5条回答
  •  借酒劲吻你
    2020-12-05 07:47

    Instead:

    public class PhotosFragment extends Fragment
    

    You can use:

    public class PhotosFragment extends ListFragment
    

    It change the methods

        @Override
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
            ArrayList listContact = GetlistContact();
            setAdapter(new ListviewContactAdapter(getActivity(), listContact));
        }
    

    onActivityCreated is void and you didn't need to return a view like in onCreateView

    You can see an example here

提交回复
热议问题