0

onActivityCreated is deprecated, below is the code I have written, what could be the alternative method and how can I rewrite the code below

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

    ListView homeListView = (ListView) getActivity().findViewById(R.id.home_list);
    homeListView.setAdapter(new BaseAdapter() {
        @Override
        public int getCount() {
            return 3;
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            return LayoutInflater.from(getActivity()).inflate(R.layout.list_item_home, null);
        }
    });
}
  • 1
    Usually, in a fragment, I configure the UI in `onViewCreated()`. – CommonsWare Nov 06 '21 at 20:36
  • 2
    Does this answer your question? [onActivityCreated deprecation : how to add fragments as observers of MainActivity using NavigationComponent](https://stackoverflow.com/questions/64174868/onactivitycreated-deprecation-how-to-add-fragments-as-observers-of-mainactivit). Furthermore, here is some hint: https://developer.android.com/reference/androidx/fragment/app/Fragment#onActivityCreated(android.os.Bundle) – Honza Zidek Nov 06 '21 at 20:43
  • a side note: i would suggest using a recyclerView instead of a listView and you will encounter no issues – Mahmoud Omara Nov 06 '21 at 20:50

0 Answers0