Search code examples
javaandroidandroid-fragmentsfragmentexpandablelistview

this keyword in Fragment is not getting implemented while


I have created two Fragments and the destination Fragment has a an Expandable List View for which there is an Adapter class as well. And when I'm trying to pass this keyword for context which is one of three parameters, it is not working. Can anyone please guide me where I went wrong.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    //Initializations
    expandableListView=view.findViewById(R.id.expand_list);

    content_collection();

    //listadapter
    listAdapter=new ExListAdapter(this, branches,branchntopic);

    expandableListView.setAdapter(listAdapter);
}

Solution

  • You can go for getActivity() or getContext() instead of using this. Since you are using fragment you cannot pass this keyword as Context.