I'm new to Android and I'm trying to create a GridView inside a Fragment. But the line
addressGrid.setAdapter(new Adapter(this));
keeps giving me an error. In my code:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_name, container, false);
addressGrid = (GridView) rootView.findViewById(R.id.gridView1);
addressGrid.setAdapter(new Adapter(this));
return rootView;
}
I've tried to replace the (newAdapter(this)); with
(new Adapter(getActivity()));
and
(new Adapter(getContext()));
which are referenced on the Android Developer site but neither seem to work. I'm really hoping someone can help me figure out why I am getting this error and how to fix it. Thank you in advance!