Skip to content Skip to sidebar Skip to footer

Create A Gridview Of Images Inside A Fragment

I am trying to create a Grid View inside a Fragment. I have implemented the adaptor class and the respective overriden methods. But while running it throws an exception in the line

Solution 1:

Change this line

GridViewgridView= (GridView) (getActivity().findViewById(R.id.ocrgridview));

To

GridViewgridView= (GridView) v.findViewById(R.id.ocrgridview); //Note "v" not activity

Solution 2:

getActivity ()

Return the Activity this fragment is currently associated with.

But

View v

Getting a reference to thevin layout file.

That's why we call second approach instead of first . You can visit below for better answer

Difference between getActivity() and view in Fragment

Post a Comment for "Create A Gridview Of Images Inside A Fragment"